- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2020 08:34 AM
Hi there,
So in our situation, we have an external system with which we need to synchronize cases opened in ServiceNow. We have created a business rule in order to do so, in which javascript code is used to do a POST or PUT depending on whether the case was inserted or updated. Now, the business rule runs before the database operation, at which point we can check if the case is a new record with current.isNewRecord().
The problem is that sometimes, on our end, the process stalls for some reason, like waiting for the access token or some other thing, which in turn stalls in the ServiceNow instance because it is stuck waiting for the processing to be done on our end.
We would like to switch the business rule to async so that it runs after the database processing and doesn't block ServiceNow, but we can't figure out how to verify if the operation done on the case was an insert or an update at that point in the execution.
Can someone point me towards a solution to do this in an async business rule?
Thanks in advance!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2020 01:03 PM
Hmm...so the condition builder still works for async BR in terms of changes and changes to/changes from, are you able to do anything with that?
Meaning...it may sound like you need two BRs, one where condition is created changes (which would mean the record is new), then another BR with other conditions (if applicable), but not the created changes condition. So you'd use that to determine if insert or update.
The condition builder and condition field (advanced view) both support the changes(), changesTo(), and changesFrom() methods.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2020 08:36 AM
Hi,
can you try to print current.operation() in the business rule; it should give whether it is insert or update
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2021 10:52 PM
current.operation() does not work for async Business Rule. It will work fine for before and after Business Rule.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2020 08:37 AM
Hi,
I believe these will still work (example):
if(current.operation() == "update") {
current.updates ++; }
if(current.operation() == "insert") {
current.updates = 0; }
Please mark reply as Helpful/Correct. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2020 12:29 PM
Hi thanks for the answers, I tried to log the value of current.operation() and it's null, the operation() method doesn't seem to work when the business rule is set to run async. It returns correct values if we set it to run before or after database operations though.