setLimit() is not working

partner_asha_a_
Mega Contributor

Hi All,

Please find the below script.I want to clear 'assigned to' field from 20k records,for that I need a script that will take 500 or 1000 records at a time .I have Used the function setLimit , but when running the script it is clearing the value from all records irrespective of the limit I have given. Can anyone please check on this.

var queryString = "hardware_status=retired^assigned_toISNOTEMPTY";
var asset= new GlideRecord('cmdb_ci_computer');
asset.addEncodedQuery(queryString);
asset.query();
while(asset.next())
{
gs.log('asset record cleared : '+asset.serial_number);
asset.setLimit(500);
asset.assigned_to="";
asset.update();
}

Thanks in advance!

1 ACCEPTED SOLUTION

Shane J
Tera Guru

I believe your setLimit() needs to be before the asset.query(); line.

 

View solution in original post

6 REPLIES 6

Shane J
Tera Guru

I believe your setLimit() needs to be before the asset.query(); line.

 

Thank you..it is working 🙂

VigneshMC
Mega Sage

It has to be added before query

var queryString = "hardware_status=retired^assigned_toISNOTEMPTY";
var asset= new GlideRecord('cmdb_ci_computer');
asset.addEncodedQuery(queryString);

asset.setLimit(500);
asset.query();
while(asset.next())
{
gs.log('asset record cleared : '+asset.serial_number);

asset.assigned_to="";
asset.update();
}

Thanks

Thank you..it is working 🙂