Business rule causing infinite loop - REST API integration

Jehiellb
Giga Contributor

I have an REST API integration between SN and Optanix that I am trying to get working correctly.  

Here is the info:
I have a Business Rule that get the comments that was entered and send via REST API to Optanix using PUT method.
When I posted a comment from Optanix and send to SN, what will SN does is it will send that comment back to Optanix.


The issue is that both side sees the comment as a new comment and starts to keep updating the same comment repeatedly.

My BR When to run:
find_real_file.png

I tried using before Update, after Update both failed and async too 😞

My BR conditions:
find_real_file.png

 

My BR Script: 

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

	try { 
		gs.log("SN - Sample TEST API Update");
		var r = new sn_ws.RESTMessageV2('Optanix Incident Management', 'Optanix - Incident PUT');
		r.setStringParameterNoEscape('number', "number: " + current.number + ", sys_id: " + current.sys_id);
		r.setStringParameterNoEscape('correlation_id', current.correlation_id);
		r.setStringParameterNoEscape('incident_state', current.incident_state);
		r.setStringParameterNoEscape('description', current.description);
		r.setStringParameter('work_notes', current.work_notes.getJournalEntry(-1).replace(/(\r\n|\n|\r|_123STREAMENTRY321_)/gm,""));
		r.setStringParameter('comments', current.comments.getJournalEntry(-1).replace(/(\r\n|\n|\r|_123STREAMENTRY321_)/gm,""));
		r.setStringParameterNoEscape('priority', current.priority );
		r.setStringParameterNoEscape('category', current.category);
		r.setStringParameterNoEscape('impact', current.impact);
		r.setStringParameterNoEscape('short_description', current.short_description);

		//override authentication profile 
		//authentication type ='basic'/ 'oauth2'
		//r.setAuthenticationProfile(authentication type, profile name);

		//set a MID server name if one wants to run the message on MID
		//r.setMIDServer('MY_MID_SERVER');

		//if the message is configured to communicate through ECC queue, either
		//by setting a MID server or calling executeAsync, one needs to set skip_sensor
		//to true. Otherwise, one may get an intermittent error that the response body is null
		//r.setEccParameter('skip_sensor', true);

		var response = r.execute();
		var responseBody = response.getBody();
		var httpStatus = response.getStatusCode();
	}
	catch(ex) {
		var message = ex.message;
	}

})(current, previous);

 

Is there a way to prevent SN from sending back the comments from Optanix platform? 

What should I add/remove or change from my BR to make this work correctly?

Your help on this will be much appreciated, Thanks in advance!

 

1 ACCEPTED SOLUTION

Manoj Kumar16
Giga Guru

Please add - gs.getSession().isInteractive()  in the condition of your business rule. 

find_real_file.png

 

View solution in original post

5 REPLIES 5

Tony Chatfield1
Kilo Patron

Hi,

The loop exists as there is poor configuration at both ends and I would exclude any update made by your integration account (I assume there is a dedicated one), and ensure similar changes are also made on the other platform.

As Kumamano indicated, there are some BR's scripts that should only be run by interactive users, but this may not always be the case if you have workflow or automation underpinning the SNC side (and these updates\changes need to be passed back to the other party).