The CreatorCon Call for Content is officially open! Get started here.

Programatically create demo data with fixed Number values from scoped app

mikehall
ServiceNow Employee
ServiceNow Employee

My requirement is to create a set of demo data (like incidents) for my scoped app as though the records were created X number of days ago.  Therefore, I am programmatically setting sys_id, Number, and dates.

 

I am able to set sys_id and dates, but not set the Number value unless I turn off workflows/BRs, which is only working from Global scope, not from my app scope.  I'd prefer to let workflows/BRs run anyway, so my issue is not that setWorkflow fails in scope, but that I can't set the Number from within scope.  Any thoughts?

Code sample:

var gr = new GlideRecord('incident');
gr.initialize();
gr.setNewGuidValue('12345678901234567890123456789012'); // WORKS
gr.autoSysFields(false); // WORKS
gr.setValue('sys_updated_on', '2020-01-01 00:00:00'); // WORKS
gr.setWorkflow(false); // ERROR IN APP SCOPE
gr.number = 'INC0011196'; // IGNORED
gr.caller_id = gs.getUserID(); // WORKS
gr.insert(); // WORKS, BUT WITH AUTO-GENERATED NUMBER 😩
}

7 REPLIES 7

mikehall
ServiceNow Employee
ServiceNow Employee

please see the script that was added

@mikehall 

 

I suggest you work with your colleagues on the PT support team. You can change the number field after records are created. See:

 

Auto Numbering

 

good luck.

Bert_c1
Kilo Patron

You can also change the value in the sys_number_counter table for table "incident" to start auto-numbering at that value.