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

also update your BR order so that it will run in the end.

I set the priority of the BR to 1,000,001 and the Order to 1,000,001.  Hopefully that puts it at the end.

This is a dev instance so only the default BR's exist.  That being said, searching for the Incident table there are nearly 2k BR's on the Incident table.

So after updating the order still triggering twice?

yep

Can you comment the current.update() and put a gs.log there ? share the log results