Does current.operation() work with Async Business Rule.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2022 03:45 PM
Hi, I am creating an Async Business Rule which is calling a REST API. Business Rule is supposed to run on insert and update. In the script section, I wanted to check if the current operation is insert or update. For that I am using the following condition:
if(current.operation() == 'insert') {do something}
else if(current.operation() == 'update') {do something}
However, when this business rule runs, every time current.operation() returns null. This code is perfectly working with an after business rule but not with an Async business rule. It would be great if someone can help me out in explaining if it will work or not and if it does not work with Async BR, what other approach should I follow. Thank you in advance!
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2022 07:37 AM
Interesting.
I was able to find 2 OOB business rules that run Async and have current.operation() used in the script.
Maybe your script does work right, the null is probably appearing because the script is being executed at a later time?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2022 08:04 AM
Hi,
I have faced he same issue for async business rule and it not worked for me.
For that I did set the variable Action as insert or update based on the condition and I have used insert and update on the if loop it works for me.
Example:
var action= 'Create';
if (current.order_id) {
action= 'Update';
}
Hope you it helps you.
Please Mark ✅ Correct/helpful if applicable, Thanks!!
Regards
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2022 08:51 AM
Hi
If it is resolved please Mark ✅ Correct as well so that it will displays in top search and users will get benefit if they have similar question.
Regards
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar