Application Development Fundamentals Class - no test records and no instructions on how to create

litchick10
Tera Guru

I'm taking the ServiceNow Application Development Fundamentals On Demand Class and am at module 4 labs which keep instructing me to open records but no records exist and I cannot find where they generated records. I've searched the entire handbook on inkling for create, record or generate and found nothing telling us how to generate records for the labs.  Any help you can provide would be greatly appreciated.  I guess I'm looking for how to randomly generate 50-100 records. 

1 ACCEPTED SOLUTION

I found the script: Solved: Unable to find Generate Random NeedIt Records Scri... - ServiceNow Community

Here is my modified script if anyone else wants to use it: 

var recordsToMake = 50;
// Declare and initialize variables used in the script
var genNIRec;
var i;
//UPDATE HERE
var tableName = "x_cdltd_loaner_req_loaner_request";
var requestTypeArray = ["cmdb_ci_computer", "cmdb_ci_mobile_device", "cmdb_ci_projector"];
var depotArray = ["ny", "london", "ba", "sc", "singapore", "sydney", "other"];
var depotOtherArray = ["portland", "vancouver", "taiwan"];
var stateArray = ["13", "14", "15", "16", "17", "18", "3"];
var pickDate = 1;
//requesters
var requestedForArray = [{
    "name": "Fred Luddy",
    "email": "fred.luddy@example.com"
}, {
    "name": "Beth Anglin",
    "email": "beth.anglin@example.com"
}, {
    "name": "Joe Employee",
    "email": "joe.employee@example.com"
}];
var pickUser = 10;


//For loop to create records
for (i = 0; i < recordsToMake; i++) {

    //Create an empty record for the table
    genNIRec = new GlideRecord(tableName);
    genNIRec.newRecord();

    //Select a random value from the requestType array and set the Request Type field value (choice)
    var selectRequestType = requestTypeArray[(Math.floor(Math.random() * 3))];
    genNIRec.setValue("item_type", selectRequestType);

    //Select a random value from the depot array and set the depot field value (choice)
    var selectDepotType = depotArray[(Math.floor(Math.random() * 7))];
    genNIRec.setValue("depot", selectDepotType);

    if (selectDepotType == 'other') {
        //Select a random value from the depotOther array and set the Depot Other field value (choice)
        var selectDepotOtherType = depotOtherArray[(Math.floor(Math.random() * 3))];
        genNIRec.setValue("other", selectDepotOtherType);
    }

    //Set the Short description field value (string)
    genNIRec.setValue("short_description", "Automatically created requests: " + selectRequestType);

    //Set the Start date needed field value (date/time) to a date between yesterday and seven months ago
    var startNow = new GlideDateTime();
    pickDate = (Math.floor(Math.random() * 210) + 1);
    startNow.addDaysUTC(-pickDate);
    genNIRec.setValue("start_date", startNow.getDate());

    //Set the End date needed field value (date/time) to a date between start date and 2 months from now
    var endNow = new GlideDateTime();
    pickDate = (Math.floor(Math.random() * 60) + 1);
    endNow.addDaysUTC(+pickDate);
    genNIRec.setValue("end_date", endNow.getDate());

    //Set the Requested for field value (reference) by selecting a random user from requestedForArray.
    //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.requested_for.setDisplayValue(requestedForArray[pickUser].name);

    //Set the State field random value (choice) to Requested
    var selectStateType = stateArray[(Math.floor(Math.random() * 7))];
    genNIRec.setValue("state", selectStateType);

    //Insert the new record into the table
    genNIRec.insert();
}

View solution in original post

6 REPLIES 6

I found the script: Solved: Unable to find Generate Random NeedIt Records Scri... - ServiceNow Community

Here is my modified script if anyone else wants to use it: 

var recordsToMake = 50;
// Declare and initialize variables used in the script
var genNIRec;
var i;
//UPDATE HERE
var tableName = "x_cdltd_loaner_req_loaner_request";
var requestTypeArray = ["cmdb_ci_computer", "cmdb_ci_mobile_device", "cmdb_ci_projector"];
var depotArray = ["ny", "london", "ba", "sc", "singapore", "sydney", "other"];
var depotOtherArray = ["portland", "vancouver", "taiwan"];
var stateArray = ["13", "14", "15", "16", "17", "18", "3"];
var pickDate = 1;
//requesters
var requestedForArray = [{
    "name": "Fred Luddy",
    "email": "fred.luddy@example.com"
}, {
    "name": "Beth Anglin",
    "email": "beth.anglin@example.com"
}, {
    "name": "Joe Employee",
    "email": "joe.employee@example.com"
}];
var pickUser = 10;


//For loop to create records
for (i = 0; i < recordsToMake; i++) {

    //Create an empty record for the table
    genNIRec = new GlideRecord(tableName);
    genNIRec.newRecord();

    //Select a random value from the requestType array and set the Request Type field value (choice)
    var selectRequestType = requestTypeArray[(Math.floor(Math.random() * 3))];
    genNIRec.setValue("item_type", selectRequestType);

    //Select a random value from the depot array and set the depot field value (choice)
    var selectDepotType = depotArray[(Math.floor(Math.random() * 7))];
    genNIRec.setValue("depot", selectDepotType);

    if (selectDepotType == 'other') {
        //Select a random value from the depotOther array and set the Depot Other field value (choice)
        var selectDepotOtherType = depotOtherArray[(Math.floor(Math.random() * 3))];
        genNIRec.setValue("other", selectDepotOtherType);
    }

    //Set the Short description field value (string)
    genNIRec.setValue("short_description", "Automatically created requests: " + selectRequestType);

    //Set the Start date needed field value (date/time) to a date between yesterday and seven months ago
    var startNow = new GlideDateTime();
    pickDate = (Math.floor(Math.random() * 210) + 1);
    startNow.addDaysUTC(-pickDate);
    genNIRec.setValue("start_date", startNow.getDate());

    //Set the End date needed field value (date/time) to a date between start date and 2 months from now
    var endNow = new GlideDateTime();
    pickDate = (Math.floor(Math.random() * 60) + 1);
    endNow.addDaysUTC(+pickDate);
    genNIRec.setValue("end_date", endNow.getDate());

    //Set the Requested for field value (reference) by selecting a random user from requestedForArray.
    //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.requested_for.setDisplayValue(requestedForArray[pickUser].name);

    //Set the State field random value (choice) to Requested
    var selectStateType = stateArray[(Math.floor(Math.random() * 7))];
    genNIRec.setValue("state", selectStateType);

    //Insert the new record into the table
    genNIRec.insert();
}

Okay, understood.