Adding comments on incident using Background script

Geetha9
Tera Contributor

Hello,

 

Iam adding comments on incident using background scriprt:
var gr = new GlideRecord("incident");
gr.addEncodedQuery('numberININC0000002,INC0000003,');
gr.query();
while(gr.next())
{
gr.setValue('state', 1);
gr.comments='hello world';
gr.setWorkflow(false); // Bypass business rules and workflows
gr.update();
}

 

State is getting changed, but comments are not added in the incident activity.

 

How to add comments on incident using background script?

 

3 REPLIES 3

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Geetha9 

 

https://www.servicenow.com/community/developer-forum/i-want-to-insert-quot-additional-comments-quot-...

https://www.servicenow.com/community/incident-management-forum/adding-journal-notes-to-incidents-via...

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

pratikalamkar
Tera Contributor

Hi ,
You can try below code,

var grInc = new GlideRecord('incident');
grInc.get('sys_id');
grInc.query();
while(grInc.next()) {
grInc.comments = "Comments which you want to set.";
grInc.update();
}

 

If my answer is helpful mark it as helpful or correct!

Br,

pratiksha.k

Prince Arora
Tera Sage
Tera Sage

@Geetha9 

 

Script which you have written looks good to me, there are no issues in it and it worked for me!