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 does not work 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 😩
}

3 REPLIES 3

AshishKM
Kilo Patron
Kilo Patron

Hi @mikehall,

The number column is using incremental sequence via "getNextObjNumberPadded();" on every insert. We can't stop new numbering unless we remove the default value on Task table which is parent table for incident.

You can reset the default value as empty during the demo data insertion and revert it back after work done or prepare new demo data ( recommended 😊)

 

Note: All other child table record's numbering like change, catalog task, problem will be impacted until default value is empty. 

AshishKMishra_0-1700158914354.png

-Thanks,

AshishKMishra


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

mikehall
ServiceNow Employee
ServiceNow Employee

Hi @AshishKM,

 

What do you mean by:

"prepare new demo data ( recommended 😊)"

 

Mike

as you mentioned "create a set of demo data" so after make the change for number prefix , you might need a new set of date ( just though, in case required if previous demo data cant be use due to number prefix )


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution