Use before/after/async Business Rules to invoke web services through the REST API?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2022 02:49 AM
Hello, In order to invoke web services through the REST API, we are making use of Business rules.
In the BR, for WHEN, what should we use - before or after or async for Create and update Operation?
Please share the reason for that 🙂
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2022 03:03 AM
For REST API invocation you should always go for Async BR as you do not want the user session hanging till you get the response. Things will happen in the back-end
You can define all actions under 3 phases.
Phase 1: Client Side Actions : Before hitting the database whether it is read/create/update/delete if you need to do anything use Before BR. Now it depends when you want to do the operation, before a new record gets created then use before insert. Before any update is made (insert is also considered as update).
Phase 2: Updating the database: When you want to do any operations after the database operation is done, because you want to make sure that database operation must happen then only you should do that operation. If there is any issue during the update and update does not happen then your operation will not take place.
Phase 3: Mostly used for notifications: When all operations are done now the phase comes to let others know that operation is done. Script Actions.
Async: It works mostly as an after business rule, but it is queued like a scheduled job which scheduled to run as soon as possible without engaging the user session. It is used for processes which may take time eg integration as it communicates with system outside ServiceNow, the journey may be difficult and lengthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2022 03:10 AM
Hi there!
Use Async Business Rule for your requirement.
Regards,
Palak

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2022 03:20 AM
Hi
For your scenario 'Async' Business rule should be better approach.
Reason : Once an insert or update operation is done async business rule will run in background and control is returned back to user immediately.
Why not Before BR : If the insert or update operation fails, still the business rule will run and web services are invoked
Why not After BR : Once an insert or update operation is done, after business rule will wait till the entire invoking of web services is done then only the control is returned back to user so it will be bad user experience.
Mark as correct and helpful if it solved your query.
Regards,
Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2022 03:49 AM
Hi
It really depends on your use case, usually recommended option is to go with an Async BR as most of the others have commented here in the chat but again do consider an After business rule if you need the real-time response being used to drive something on the current form and not wait.
Async BR
Pros - Rest call happens in the backend and the system does not hold user interaction until we receive the synchronous response from the target.
Cons- High dependency on the system scheduler as these jobs are executed in the system scheduler based on the availability of the worker nodes on the system.
Definitely use this if the volume is high
After BR
Pros - REST calls happen in real-time, you can utilize the response received on the form if there is a use to have a real-time update posted on the record.
Cons - Holds the user interaction until the REST execution is completed.
Don't use this if the volume is high
The third option - Flow
Consider using a flow, you can make rest calls in your script action to execute the REST calls.
(you need an integration hub license to run a REST call in the flow)
If the answer has helped you, please mark the answer correct/helpful. Thank you.
-Harneet
ServiceNow Certified Technical Architect