-
-
Save wave-inguane/d48c399f08318bf678aa5d5825fd0d68 to your computer and use it in GitHub Desktop.
Automation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******************************************************************************************************************************* | |
* 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":"fred.luddy@example.com"},{"name":"Beth Anglin","email":"beth.anglin@example.com"},{"name":"System Administrator","email":"admin@example.com"}]; | |
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); | |
genNIRec.newRecord(); | |
//Select a random value from the requestType array and set the Request Type field value (choice) | |
selectRequestType = requestTypeArray[(Math.floor(Math.random() * 3))]; | |
genNIRec.setValue("u_request_type",selectRequestType); | |
//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); | |
rightNow.addDaysUTC(pickDate); | |
genNIRec.setValue("u_when_needed",rightNow.getDate()); | |
//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)); | |
genNIRec.u_requested_for.setDisplayValue(requestedForArray[pickUser].name); | |
genNIRec.setValue("u_requested_for_email",requestedForArray[pickUser].email.toString()); | |
//Set the Priority field value (choice) to a random value | |
genNIRec.setValue("priority",(Math.floor(Math.random()*5)+1)); | |
//Set the State field value (choice) to Requested | |
genNIRec.setValue("state",13); | |
//Insert the new NeedIt record into the table | |
genNIRec.insert(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment