how to update state field of the records created 7 days ago weekly using scheduled script execution

Babu
Kilo Contributor

how to update state field of the records created 7 days ago weekly using scheduled script execution.here is my script ..

var ga= new GlideRecord('x_465600_elegant_i_elegant_requests');
ga.addQuery('active', 'true');
ga.addQuery('created','=',gs.daysAgo(7));
ga.query();

while (ga.next());

if (ga.getValue('state',1)){               // if its state is still open 
ga.setValue('state',0);                   // update them to pending 
ga.update();

when m executing the above script it is creating a new record for that record it is setting the state value 0(pending).but i need to update all the records open- to- pending state created 7 days ago...   

2 REPLIES 2

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Have a look at this article I wrote a while ago. With this, you could create your filter from a list and using that query for your script:
Utilizing the breadcrumb on lists to generate your query

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Did this solve your question? Or do we need to follow-up on this?

Please mark this answer as correct if it solves your question. This will help others who are looking for a similar solution. Also marking this answer as correct takes the post of the unsolved list.
Thanks.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn