Copy comments between Incident and Case

haraldkvangarsn
Tera Contributor

Hi

Why: We want all customer interaction to happen through the related Case record.
How: Business Rule on both the Incident and Case table (also tried on the task table, with same issue).
Issue: The code works, but since it is generating a loop on the source record, that record get's two entries in the Comments section. One from the Source table (where the user enters the comment or email) and then one from the replicating table (for instance Incident). Then the BR seems to stop (as it either seems to detect a loop, or no changes are made to the "additional comments" field. In the case above Case will have to identical Comments while the Incident has one. If the update happens on the Incident table the INC will have two identical comments, and case will have only one.

How can I correct this looping behaviour?
I've tried matching the comments with getJournalEntry(1), but they seem to mismatch at all times.
Is the answer to create an additional field u_last_comment and match that field to the last JournalEntry? Anyone have any good ideas? 🙂

Bussiness rules are running;
When; before 
On: Update
Filters: Additional comments = changes
State  = not closed/cancelled

Business Rule on Case table

(function executeRule(current, previous /*null when async*/) {
		
	var inc = new GlideRecord('incident');
	inc.addQuery('sys_id', current.incident.sys_id);
	inc.addQuery('state','NOT IN',ServiceManagementIntegrationConstants.NO_INC_SYNC_CASE_STATE.join());
	inc.query();
	while (inc.next()) {
		
		inc.comments = current.comments;
		inc.update();		
	}
	
})(current, previous);

Business Rule on Incident Table

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

			var cs = new GlideRecord('sn_customerservice_case');
				cs.addQuery('incident', current.sys_id);
				cs.addQuery('state','NOT IN',ServiceManagementIntegrationConstants.NO_INC_SYNC_CASE_STATE.join());
				cs.query();
					while (cs.next()) {
						cs.comments = current.comments;
						cs.update();		 
						}

})(current, previous);
1 ACCEPTED SOLUTION

prashanth2
Kilo Guru

Hey,

Add gs.getSession().isInteractive() in the condition field of the BR and try it might solve the issue.

https://developer.servicenow.com/dev.do#!/reference/api/quebec/server/no-namespace/c_GlideSystemScop...

 

If this has helped you in anyway please mark the reply as helpful/correct.

Regards,

Prashanth

View solution in original post

1 REPLY 1

prashanth2
Kilo Guru

Hey,

Add gs.getSession().isInteractive() in the condition field of the BR and try it might solve the issue.

https://developer.servicenow.com/dev.do#!/reference/api/quebec/server/no-namespace/c_GlideSystemScop...

 

If this has helped you in anyway please mark the reply as helpful/correct.

Regards,

Prashanth