Copy sys_choice values from One table to other

chandu-snow
Mega Contributor

Hi All,

I'm trying to copy specific(not all) 'sys_choice' Category values of Incident table to another custom table --

 

I'm using the below job/script to insert same records as incident - However it is creating only one record in sys_choice with new table value. Am i missing anything below?

 

var gr = new GlideRecord('sys_choice');
gr.addEncodedQuery('nameSTARTSWITHINCIDENT^elementSTARTSWITHcategory^dependent_valueSTARTSWITHdata');
gr.query();

while(gr.next()) {

var gr1 = new GlideRecord('sys_choice');
gr1.initialize();
gr1.name = 'u_finance';
gr1.element = 'u_task_category';
gr1.label = gr.label;
gr1.value = gr.value;
gr1.dependent_value = gr.dependent_value;
gr1.insert();
}

1 ACCEPTED SOLUTION

Pradeep,

Even the Rowcount is 20 in the script.

Anyhow i figured the root cause of this issue. There was a BR in background "choice unload" causing this script to not execute completely. I have added setWorkflow(false) in my Script and it worked now. Thank you responding here. Appreciate it 🙂

View solution in original post

4 REPLIES 4

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Chandu,

 

Can you apply the same filter i.e nameSTARTSWITHINCIDENT^elementSTARTSWITHcategory^dependent_valueSTARTSWITHdata' and from UI and check the count of records once?

 

Thanks,

Pradeep Sharma

chandu-snow
Mega Contributor

Pradeep,

 

The count is 20 in the UI. but when i run the job, it is getting only 1 record inserted.

Thanks for the update. Can you log the Row Count in the script as well and check it once?

Pradeep,

Even the Rowcount is 20 in the script.

Anyhow i figured the root cause of this issue. There was a BR in background "choice unload" causing this script to not execute completely. I have added setWorkflow(false) in my Script and it worked now. Thank you responding here. Appreciate it 🙂