Background script updating only one record at a time;

Meenal Gharat
Giga Guru

Hi All,

I am trying to do Mass update on my Gb Case using background script.

Everytime when I run the script it updates only one record how can i do mass update on 80000 records?

below is the script.

doUpdate();

function doUpdate()
{
var count= new GlideRecord('u_gbs_case_management');
count.addEncodedQuery('state=5^u_resolvedISEMPTY');

count.setLimit(10);
count.query();
if(count.next());
{

count.u_resolved = count.closed_at;
count.update();
}
}

 

any advice would be helpful.

Thanks and regards,

Meenal

1 ACCEPTED SOLUTION

bint
Giga Contributor

Hi Meenal,

 

Use setWorkflow(false) command. it will help you to execute the command smoothly.

please go through the link for more details:

https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=r_GlideRecord-setWorkFlow_Boolean

 

Run the code in below format:

doUpdate();

function doUpdate()
{
var count= new GlideRecord('u_gbs_case_management');
count.addEncodedQuery('state=5^u_resolvedISEMPTY');

count.setLimit(10);
count.query();
if(count.next());
{

count.setWorkflow(false); 

count.u_resolved = count.closed_at;
count.update();
}
}

 

 

Hope this will resolve your issue. 🙂

View solution in original post

13 REPLIES 13

bint
Giga Contributor

Hi Meenal,

 

Use setWorkflow(false) command. it will help you to execute the command smoothly.

please go through the link for more details:

https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=r_GlideRecord-setWorkFlow_Boolean

 

Run the code in below format:

doUpdate();

function doUpdate()
{
var count= new GlideRecord('u_gbs_case_management');
count.addEncodedQuery('state=5^u_resolvedISEMPTY');

count.setLimit(10);
count.query();
if(count.next());
{

count.setWorkflow(false); 

count.u_resolved = count.closed_at;
count.update();
}
}

 

 

Hope this will resolve your issue. 🙂

Hi bint,

Still no luck.

I tried using setWorkflow() in my code, still it is updating single record at a time.

Thanks and Regards,

Meenal

JayGervais
Kilo Sage

Hi Meenal, 

I had a background script that worked great in my dev instance but when I went to do it in test I ran into a similar issue. It would update one record and stop. I added setWorkflow(false) and it seemed to work when trying it in sandbox. What exactly does this do?

Regards,

Jay

setWorkflow(false) make sure that none of your business rule runs which is written on the table.

Thanks 

Meenal