- 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 08:28 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2021 08:32 AM
can you search message in logs maybe another message is presnet and also check if you have setworkflow line in your code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2021 09:16 AM
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.