Whenever work notes / comments changes on the incident, it should get copied to all associated incident tasks. Also when work notes of incident task changes it should get copied to the incident. Also no notification should trigger during this activit

punitchourey
Tera Contributor

Hi All,

We have below requirement:

 

Whenever work notes / additional comments changes on the incident, it should get copied to all associated active incident tasks. Also when work notes of incident task changes it should get copied to the incident work notes. Also no notification should trigger from the record at which the work notes / additional comments are getting copied. 

 

Thanks

1 ACCEPTED SOLUTION

Hi Punit,

I believe you must be using business rule to trigger the REST/SOAP endpoint?

So basically you don't want to trigger API call when something updates from script but only when it is updated in some user' session?

If yes then you need to add this in the BR condition which triggers the API call

gs.getSession().isInteractive()

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

View solution in original post

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you would require business rule and avoid the loop by using setWorkflow(false)

Regards
Ankur

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

Brad Bowman
Kilo Patron
Kilo Patron

We are doing this with 2 after update business rule on the incident table, and 2 on the incident_task table.  When Work notes changes and Updated by is not system (prevents recursion and unwanted system updates).  The second rule is the same, but when Additional comments changes, though you might be able to combine these.  

1) Copy Incident Work Notes to Active Incident Tasks

var inctask = new GlideRecord('incident_task');
inctask.addQuery('incident', current.sys_id);
inctask.addQuery('active', 'true');
inctask.query();
while(inctask.next()){
var curWN = current.work_notes.getJournalEntry(1); //gets the most recent work note
var curTN = current.number;
var curAG = current.assignment_group.name;
if(inctask.work_notes.getJournalEntry(1) == '' || curWN.indexOf(inctask.work_notes.getJournalEntry(1)) <0){
var newWN = curTN + " - assigned to " + curAG + "\n\n" + curWN;
inctask.work_notes = newWN;
inctask.update();
}
}

This appends the incident number and assignment group so that it's obvious it was copied, and checks to be sure it's not already there to prevent recursion with the business rule running on incident task

2) Copy Incident Task Work Notes to Incident

var inc = new GlideRecord('incident');
if(inc.get(current.incident.sys_id)){
var curWN = current.work_notes.getJournalEntry(1);
var curTN = current.number;
var curAG = current.assignment_group.name;
if(inc.work_notes.getJournalEntry(1) == '' || curWN.indexOf(inc.work_notes.getJournalEntry(1)) <0){
var newWN = curTN + " - assigned to " + curAG + "\n\n" + curWN;
inc.work_notes = newWN;
inc.update();
}
}

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

punitchourey
Tera Contributor

Thanks Ankur, Brad and Pradeep. It is working now.

However i have another requirement that when work notes/ additional comments get copied to incident task, we have a notification which triggers on update of work notes on incident task.

We want that notification to be triggered only when work notes on incident task is entered not in case of it is copied from incident. Also the same requirement is for incident as well.

I tried set workflow false however it do not work.

Thanks.