Update Record in Business Rule without Triggering Business Rule

Chris McIntosh
Kilo Contributor

Hey All,

I have a business rule that triggers on the creation or update of the incident table.

In the business rule I make a REST request and I would like to update the incident with some info from the REST response.

The trouble is when I update the record it triggers the business rule again.

 

Here is a sample of my code:

 

(function executeRule(current, previous /*null when async*/ ) {
    try {
        var post_request = {
            'event': 'created',
            'incident_number': current.getValue('number'),
            'short_description': current.getValue('short_description'),
            'description': current.getValue('description'),
            'sys_id': current.getValue('sys_id'),
        };

        var restMessage = new sn_ws.RESTMessageV2();

        restMessage.setHttpMethod("post");
        restMessage.setEndpoint("REST_HOST");
        restMessage.setRequestHeader('Content-Type', 'application/json');

        restMessage.setRequestBody(JSON.stringify(
            post_request
        ));
        var response = restMessage.execute();
	var responseObj = JSON.parse(response.getBody()); 
	current.setValue('description', responseObj.value + ' ' + current.getValue('description'));
	current.update('updating with metadata');
    } catch (ex) {
        var message = ex.message;
        gs.error(message);
    }
})(current, previous);
1 ACCEPTED SOLUTION

Pranesh072
Mega Sage
Mega Sage

You can either use gs.isInteractive() condition in every other BR 

or

You can use current.setWorkflow(false) in current BR which will prevent the other BRs to run

View solution in original post

17 REPLIES 17

Hmm, isInteractive and setWorkflow(false) both seem to be failing.  

Any ideas other workarounds?

can you share the code how you are using these functions?

Yes definitely.

This is on an async business rule on the Incident table, triggered by Insert or Update

The way its working now, it still fires the update event when this runs.

I tried using gs.isInteractive() in an if condition, but it was always set to false even though I was creating incidents through the UI.

 

(function executeRule(current, previous /*null when async*/ ) {
        try {
            var post_request = {
                'event': 'created',
                'incident_number': current.getValue('number'),
                'short_description': current.getValue('short_description'),
                'description': current.getValue('description'),
                'sys_id': current.getValue('sys_id'),
            };

            var restMessage = new sn_ws.RESTMessageV2();

            restMessage.setHttpMethod("post");
            restMessage.setEndpoint("HOST");
            restMessage.setRequestHeader('Content-Type', 'application/json');

            restMessage.setRequestBody(JSON.stringify(
                post_request
            ));
            var response = restMessage.execute();
            var responseObj = JSON.parse(response.getBody());
            current.setValue('description', '{"issue_number": "' + responseObj.issue_number + '"}' + current.getValue('description'));
			current.setWorkflow(false);
            current.update();
			
        } catch (ex) {
            var message = ex.message;
            gs.error(message);
        }

})(current, previous);

Strange! this should not trigger anything. Can you check if there are other BR active which are running on update and they are updating something with this BR. Can you update your BR order so that it will run in the end.

 

 

Sure i'll check on other BR's thats a good idea.