Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

update worknotes of incident whenever problem task worknotes get updated

Priti18
Tera Expert

if user updates worknotes of problem task then worknotes of incident should get updated using bsuiness rule

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@Priti18 You can achieve this functionality by creating an onBefore Update business rule on Problem Task table as follows.

Screenshot 2023-04-25 at 11.46.51 PM.pngScreenshot 2023-04-25 at 11.47.57 PM.png

Here is the script for the business rule.

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    if (current.problem) {
		var incidentRec = new GlideRecord('incident');
		incidentRec.addQuery('problem_id',current.problem);
		incidentRec.query();
		while(incidentRec.next()){
			incidentRec.work_notes = current.work_notes.getJournalEntry(1);
			incidentRec.update();
		}
    }

})(current, previous);

 

Please mark this answer helpful and correct if it addresses your requirement.

View solution in original post

5 REPLIES 5

Sandeep Rajput
Tera Patron
Tera Patron

@Priti18 You can achieve this functionality by creating an onBefore Update business rule on Problem Task table as follows.

Screenshot 2023-04-25 at 11.46.51 PM.pngScreenshot 2023-04-25 at 11.47.57 PM.png

Here is the script for the business rule.

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    if (current.problem) {
		var incidentRec = new GlideRecord('incident');
		incidentRec.addQuery('problem_id',current.problem);
		incidentRec.query();
		while(incidentRec.next()){
			incidentRec.work_notes = current.work_notes.getJournalEntry(1);
			incidentRec.update();
		}
    }

})(current, previous);

 

Please mark this answer helpful and correct if it addresses your requirement.

can you please explain your script and why before update because I created my Br on after update

@Priti18 The business rule I have shared runs on Problem Task table it is an OnBefore Update business rule, you can change it to onAfter as well. The filter condition work_notes changes have been applied to only execute the script only when the work notes on the problem task is added. Inside if I am fetching all those incidents which have been originated from the problem record which is similar to the problem record on the problem task.

 

Finally I am adding the worknotes added on the problem task to the incident records.

 

Hope this helps.

 

Inside the script, I am checking if the problem task has an associated problem. 

I am wanting the incident to update when the work notes in the Problem ticket PRB is updated.  I attempted this Business rule but did not work.  I changed the table to Problem.  Dont know much about scripting but I assume it should have still worked with the current script