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

Rahul Kumar17
Tera Guru

Hi,

To update the worknotes of an incident when a worknote is added to a problem task, you can create a business rule with the following settings:

Table: Problem Task [problem_task]

When: After [Insert, Update]

Filter conditions:

  • Condition 1: Current [work_notes] is not empty
  • Condition 2: Previous [work_notes] is not equal to current [work_notes]

Note: The filter conditions above will ensure that the business rule is only triggered when the work_notes field is updated.

Script:

// Get the current problem task var currentTask = current;

// Get the associated incident var incident = new GlideRecord('incident');

incident.addQuery('number', currentTask.problem_id.number);

incident.query();

// Update the work notes of the incident

if (incident.next()) {

incident.work_notes = currentTask.work_notes;

incident.update();

}

The script above gets the current problem task and finds the associated incident using the problem_id field. It then updates the work_notes field of the incident with the value of the work_notes field of the problem task.

Make sure to test the business rule thoroughly in a non-production environment before deploying it to production.

 

Thanks,

Rahul Kumar

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar