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

Simon Hendery
Mega Patron
Mega Patron

Hi @litchick10 

 

Can you provide more detail? There are 4 labs in section 4 (4.1, 4.2a, 4.2b & 4.3). Which section of which lab are you stuck on?

4.1 - asks you to test the ESS view on an existing record at step C.1

4.2b - step 7 asks you to test the client script on an existing record

4.2b - step 10 asks you to test on a record with specific conditions

 

There are two places in 4.2a where it does say, "use existing record or create a new record" but creating records for every scenario one at a time is going to be time consuming. In most other classed, they've either given us a script to randomly generate records or have had us pull from git records for testing. 

 

Hi @litchick10 

 

I see that in Lab 3.4 (part B), you're asked to create some records (see attached).

litchick10
Tera Guru

Correct but neither of those records meet the conditions for the labs in 4. Also, I don't want to manually create records, I want to generate a random set of 50-100 records but I can't seem to find the script that was used with the needIt app. I have enough dev experience to modify the script but not enough to write a randomizer script myself.