setAbortAction(true) does not work when the business rule is fired via a REST call to incident table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2016 05:43 PM
OnBefore scripted business rule.
We have a servicenow instance that has scripted web services for our clients. We test these services using REST client to access tables like incidents.
I am trying to apply a business rule to add some constraints to a custom field on the incident table (actually it is task table).
I see the business rule is getting fired. My script logs information.
But
current.setAbortAction(true) does not really abort the operation. I still see the bad value is committed in the incident.
What is going on?
Is setAbortAction(true) only works for UI based insert/updates?
To address this question more generically - I rephrase it here
What is the best way to write a business rule that works whether it is UI based action or programmatic (e.g. updating tables via REST calls)?
Can you please share some documentation links?
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2023 10:33 AM
Okay i don't think in before BR, if we are using setAbortAction(true), the script/BR will ever work. Just think about it for a sec, before BR means the particular database operation is not performed yet and when the system finds that the flag is set to false which makes the next db action(in this case the operation our current before Business Rule is trying to perform) to not run. So that's why the script won't take effect at all.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2016 10:55 PM
Actually this is the alternate of your problem :
What you can do, you can use gs.getSession().isInteractive() if it's false means record is updating by web service, so you can set the values like :
if (!gs.getSession().isInteractive() ) { // if session is not interactive means : web service
set the values to previous values :
current.field_name = previous.field name;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2016 12:00 AM
Thanks Paramveer!
I have verified today using a different table that setAbortAction(true) aborts the operation just fine. It isn't working on the incident table.
Right now - my theory is some business rule is calling current.update() or something that commits the changes to the database so setAbortAction(true) can't do what it is supposed to do.
Earlier I tried current.state = previous.state. This should have worked. It didn't. So I am assuming current.field_name = previous.field_name will not work either. I will give it a try.
More importantly - I will try to find all the BRs and see if any script is trying to do current.udpate() type operation. That would mess things up.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2017 04:26 AM
Hi Naushad,
I'm having the same problem with the incident table when using current.setAbortAction(true). I even tried disabling all other BRs by giving it the lowest order on the BRs and using with current.setWorkflow(false).
Did you happen to find a solution for this?
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2016 12:17 AM
also try to give minimum order for your business rule so that it should abort the action before execution of other rules.