- 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-08-2021 02:08 PM
Hmm, isInteractive and setWorkflow(false) both seem to be failing.
Any ideas other workarounds?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2021 09:39 PM
can you share the code how you are using these functions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2021 07:02 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2021 07:17 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2021 07:22 AM
Sure i'll check on other BR's thats a good idea.