Skip to content

Instantly share code, notes, and snippets.

Created August 30, 2021 02:18
Show Gist options
  • Save wave-inguane/d48c399f08318bf678aa5d5825fd0d68 to your computer and use it in GitHub Desktop.
Save wave-inguane/d48c399f08318bf678aa5d5825fd0d68 to your computer and use it in GitHub Desktop.
* Generate Randon Records
Use Fix Script
//Number of NeedIt records to create
var recordsToMake = 500;
// Declare and initialize variables used in the script
var genNIRec;
var i;
var tableName = "x_58872_needit_needit";
var requestTypeArray = ["facilities","hr","legal"];
var selectRequestType = "";
var selectWhatNeeded = 3;
var pickDate = 1;
var requestedForArray = [{"name":"Fred Luddy","email":""},{"name":"Beth Anglin","email":""},{"name":"System Administrator","email":""}];
var pickUser = 10;
//For loop to create records
for (i = 0; i < recordsToMake; i++) {
//Create an empty record for the NeedIt table
genNIRec = new GlideRecord(tableName);
//Select a random value from the requestType array and set the Request Type field value (choice)
selectRequestType = requestTypeArray[(Math.floor(Math.random() * 3))];
//Set the What needed field value (choice) from the Request Type and either 1 or 2
selectWhatNeeded = (Math.floor(Math.random()*2) +1);
genNIRec.setValue("u_what_needed",selectRequestType + selectWhatNeeded);
//Set the Short description field value (string)
genNIRec.setValue("short_description", "Automatically created NeedIt request: " + selectRequestType + ", " + selectRequestType + selectWhatNeeded);
//Set the When needed field value (date/time) to a date between six months from now and six months ago
var rightNow = new GlideDateTime();
pickDate = (Math.floor(Math.random() * 366) - 182);
//Set the Requested for field value (reference) by selecting a random user from requestedForArray.
//Also set the Requested for email field value (string). The reference field cannot be set in a scoped app
//using the setValue method unless using the sys_id to set the field value. To set by display name, use
//the GlideElement setDisplayValue method. gr.<field_name>.setDisplayValue(<value>).
pickUser = (Math.floor(Math.random()*3));
//Set the Priority field value (choice) to a random value
//Set the State field value (choice) to Requested
//Insert the new NeedIt record into the table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment