- 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 11:20 AM
Make sure that you configure ASYNC business rule since you are waiting for JSON response from your REST call.
As best practise, you should create an event and call that event from a Business rule. And then associate the event to a script action. And add all your code to call REST API to script action. So that they are kept separate and async.
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2021 11:29 AM
Thanks
I am pretty new to SNOW development so I need some hand holding.
Rest Event:
Call Rest endpoint with INC Number and Sys_Id
Return data
Should my async business rule be like so:
Trigger event
Use data to update description
Update current record
Is that what you are suggesting?
I tried this as a quick workaround and it didn't appear to stop the recursion: https://hi.service-now.com/kb_view.do?sysparm_article=KB0715782
Thanks,
Chris

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2021 11:54 AM
You need to use isInteractive() in your business rule condition so that it doesn't trigger after you update current record.
The isInteractive() method checks if the current session is interactive. An example of an interactive session is when a user logs in using the log-in screen. An example of a non-interactive session is using a SOAP request to retrieve data.
To know more about this API refer isInteractive() - Developer API
REST API call is NON interactive session.
Regards,
Sachin
- 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