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

find_real_file.png

Without the update it only runs the trigger once as expected and hits the gs.error() log message

can you search message in logs maybe another message is presnet and also check if you have setworkflow line in your code.

To close this out, I had to rearchitect a bit to get it to work.

 

I made the business rule a before rule that called an event.

Additionally it only calls the event if gs.isInteractive() is true.

 

I moved the REST code to the Event and update the event from the response.

 

This prevents the BR loop.