setAbortAction(true) does not work when the business rule is fired via a REST call to incident table

naushad
Kilo Contributor

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.

9 REPLIES 9

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Naushad,



Can you give BR lowest order and try once. The only time BR will be turned off is when you update records and script contains setWorkflow(false).


BR fires fine. SetAbortAction(true) doesn't seem to abort. I tried order 1 and 10000. No luck.


paramveer
Mega Guru

you can write below condition in business rule :



gs.getSession().isInteractive() returns false if record updates from web service. In this case BR will not run.




Thanks,


Param


Hi Paramveer - Thanks for trying to help.



I am not sure why you are assuming business rule is not running. In my post nowhere I am saying business rule is not running. I am saying current.setAbortAction(true) does not abort the database operation.



Here's the scenario.


REST client (a program outside of servicenow) updates an incident by changing the value of a custom field. Say correlation_id = 20. Before this call the value is 15.



There is a business rule that is written so if value is 20 then it calls current.setAbortAction(true). I verified that call is actually made. But I see that it didn't work. The incident is still updated with correlation id = 20.



Is there other scripting API to abort operation?