- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2018 06:33 PM
Hello community.
I have a question about a very common use case in an integration with a third party system, for which I'm still unsure of the best practice approach. Here is the process:
1) Incident created in our ServiceNow instance.
2) Business rule runs to send outbound REST message to third party system.
3) REST response received, which contains the third party ref (incident number in the third party's system).
4) Response parsed, and third party ref added to correlation ID of the current record (ie the newly created incident).
Until now, I've tended do this all in a BEFORE business rule, but I realise that's probably not best practice as it means we're generating the outbound REST message before our incident has been created. The incident might for some reason fail to be created, but we would already have created the corresponding incident on the partner's system.
Is it better to do this in an AFTER business rule, or an ASYNC rule? In both cases, I'm having to use current.update() which I know is also not a good practice. But I'm using current.setWorkflow(false) beforehand, to stop recurring business rules.
I've set up a business rule that fires a REST message at a mock server I've set up in Postman, to test this out. I'm finding that the AFTER rule works best, but there might be performance issues experienced by the user if the response is delayed for some reason.
Any advice or thoughts on this?
For completeness, here is the code from my business rule:
(function executeRule(current, previous /*null when async*/) {
try {
var r = new sn_ws.RESTMessageV2('PostManMock_INC_1', 'CreateNewINC');
var incNum = current.getValue('number');
r.setStringParameterNoEscape('number', incNum);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
var parsed = JSON.parse(responseBody);
var postMockINC = parsed.client_ref;
gs.info('XXXX Postman Mock Incident: ' + current.number + ': ' + postMockINC);
current.correlation_id = postMockINC;
current.correlation_display = 'Postman Mock';
current.setWorkflow(false);
current.update();
}
catch(ex) {
var message = ex.getMessage();
}
})(current, previous);
Solved! Go to Solution.
- Labels:
-
Integrations

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2018 09:01 PM
I usually prefer creating an event and calling that event from a Business rule. And then associate the event to a script action. And add all my code to script action. So that they are kept separate ans async.
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2018 07:06 PM
I did something similar when I was building integration with Jira. I used async instead of after. I know it's not best practice to use current.update but there was not other option. It is working fine for us and that should solve your delay issue.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2018 09:01 PM
I usually prefer creating an event and calling that event from a Business rule. And then associate the event to a script action. And add all my code to script action. So that they are kept separate ans async.
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2018 07:15 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2018 11:19 AM
Please mark my response correct if it worked for you
Please mark this response as correct or helpful if it assisted you with your question.