Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Background script updating only one record at a time;

Meenal Gharat
Tera 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

Mark Skinner
Mega Guru

Hi,

 

it is because of this part

if(count.next());
{

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

 

You will need to change the if to a while

while(count.next());
{

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

Thanks

Mark

if this has helped please mark as so, if this answered your question please mark as correct

 

Hi Mark,

I tried with while 

Instead of update I'm getting Insert Operation.

 

find_real_file.png

Thanks and Regards,

Meenal

I tried with your script by changing table name and field name and it is working

 

can you please paste your scirpt:

 

doUpdate();

function doUpdate()
{
var count= new GlideRecord('incident');
count.addEncodedQuery('state=2^resolved_atISEMPTY');
count.setLimit(10);
count.query();
while(count.next());
{

count.work_notes = "Scrpt working";
count.update();
}
}

Hi,

I cannot see any reason why this would not be working. 

maybe you can add a gs.print(count.sys_id) in the while loop and then look at the records that it has updated to see if it has done what you needed.

Thanks

Mark