Scheduled Script is updating only 1 record each runtime, not mutliple records

subhadeep1618
Tera Guru

I have the below scheduled script with the objective of updating multiple records that match the given criteria.

It is scheduled to execute every 10 seconds.

In Run As field, I have given my name (I have admin access).

 

subhadeep1618_0-1690693667712.png

The script text of above screenshot is also given below:

var gr = new GlideRecord("cmdb_ci_service");
gr.addEncodedQuery(
    "service_classification=Project^end_date<javascript&colon;gs.beginningOfToday()"
);
gr.query();
while (gr.next()) {
    gr.setValue('operational_status', '6');
    gr.update();
}

But what is happening is, each time only 1 record is getting updated.

If I manually click Execute Now, then also only 1 record (1st record of GR object) is getting updated, but the rest are remaining with old value of the operational status field.

Please help me to identify what is the issue here.


Please mark this post as a solution and also as helpful, if this resolves your issue or query.

Thanks,
Subhadeep Ghosh.
6 REPLIES 6

Thank you so much @OlaN for taking so much of your time and sharing me this.

I will definitely try it out and get back to you within next week.

--

Rgds,

Subhadeep.


Please mark this post as a solution and also as helpful, if this resolves your issue or query.

Thanks,
Subhadeep Ghosh.

Sagar Pagar
Tera Patron

Hi @subhadeep1618,

 

Scripts looks fine to me. Make sure that the query is correct and returns more than 1 records.

 

If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers.
Thanks,
Sagar Pagar

The world works with ServiceNow