- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2021 11:10 AM
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);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2021 12:20 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2021 07:26 AM
also update your BR order so that it will run in the end.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2021 07:50 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2021 07:52 AM
So after updating the order still triggering twice?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2021 07:54 AM
yep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2021 08:02 AM
Can you comment the current.update() and put a gs.log there ? share the log results