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

sachin_namjoshi
Kilo Patron
Kilo Patron

You need to add condition in your business rule to verify that incident is NOT updated by Optanix platform.

I hope you have local service account for Optanix interface on your instance.

 

Regards,

Sachin

Manoj Kumar16
Giga Guru

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

find_real_file.png

 

Hi kumamano, 

Everything worked as expected. Thank you so much! 🙂

Thanks Manoj. It works with the Business Rule. But I am facing the infinite loop while using the flow designer. Help me with that.

SubashiniBala_0-1708603295780.pngSubashiniBala_1-1708603326679.png