Bulk close records with comments or worknotes

AmanPratapS7233
Tera Expert

Hi All,

 

I don't want to send email notifications and bulk close change records. Why is my fix script not updating the comments and worknotes ?

 

My code: - 

var chg = new GlideRecord('change_request');
chg.addEncodedQuery('<YOUR_ENCODED_QUERY>');
chg.query();

gs.info("Changes found: " + chg.getRowCount());

while (chg.next()) {

chg.setWorkflow(false);
chg.autoSysFields(false);

chg.state = 3;
chg.comments = "This change is bulk closed";

chg.work_notes = "This change is bulk closed";

chg.update();
}

4 REPLIES 4

Ankur Bawiskar
Tera Patron

@AmanPratapS7233 

update as this

See if any data policy is blocking the closure

var chg = new GlideRecord('change_request');
chg.addEncodedQuery('<YOUR_ENCODED_QUERY>');
chg.query();

gs.info("Changes found: " + chg.getRowCount());

while (chg.next()) {
    chg.state = 3;
    chg.comments = "This change is bulk closed";
    chg.work_notes = "This change is bulk closed";
	chg.setUseEngines(false); // disable data policy if any
    chg.setWorkflow(false);
    chg.autoSysFields(false);

    chg.update();
}

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

@Ankur Bawiskar  - used this code but, this is still sending the emails.

@AmanPratapS7233 

Did my script work to update the comments or worknotes?

how are the emails being sent?

via notifications, flow etc
when you use setWorkflow(false) it does disable the notification engine etc on that record

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

Tanushree Maiti
Tera Patron

Hi @AmanPratapS7233 

 

Try this ,

var chg = new GlideRecord('change_request');
chg.addEncodedQuery('<YOUR ENCODED_QUERY>');
chg.query();
gs.info("Changes found: " + chg.getRowCount());

while (chg.next()) {

chg.comments = "This change is bulk closed";
chg.work_notes = "This change is bulk closed";
chg.update();

var backendupdateChg = new GlideRecord('change_request');
if (backendupdateChg.get(chg.sys_id)) {
backendupdateChg.setWorkflow(false);
backendupdateChg.autoSysFields(false);
backendupdateChg.state = 3; // Closed
backendupdateChg.update();
}
}

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti