need background script to close change and update comments

great
Kilo Contributor

Hi Team,

I want to close 105 changes with additional comments" change closed manually". Please let me know the background script 

12 REPLIES 12

Mohit Kaushik
Mega Sage
Mega Sage

Hi There,

Please write a background script like this :

var chg = new GlideRecord('change_request');

chg.addQuery('state','what ever condition you want to give to filter your 105 changes');

chg.query();

while(chg.next())

{

chg.comments='change closed manually';

chg.update();

}

 

Please mark this answer as correct and helpful if it resolves the query and helpful alone if it lead you in right direction.

 

Thanks,

Mohit Kaushik

 

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

Hi ,

Thanks for reply.one doubt, where it is mentioned to change the state  to close.

please confirm the below query added,

chg.addQuery('state','numberINFG-CHG0031009,FG-CHG0031102,FG-CHG0031047,+etcc)

@great 

Please check the script I shared

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

oops sorry,

please add this line to your code inside the while loop:

chg.state=3;
chg.setWorkflow(false);

 

Thanks,

Mohit Kaushik

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)