The CreatorCon Call for Content is officially open! Get started here.

running an async business rule on delete transaction

damianfell
Tera Guru

I'm trying to trigger an advanced async business rule on deletion of a record from cmdb_rel_ci, (that calls a function from a class in a script include) but I can't pass it the current.child value as by the time the rule runs the business rule has no cognizance of the current record as it has been deleted.

The only solution I can find is to split my rule into two,

        one that runs "async" on insert and update,

        and one that runs "after" for deletes.

Can anyone suggest a more elegant solution? As ideally I want the functions to run in the background for all cases.

4 REPLIES 4

rahulpandey
Kilo Sage

Why don't you use script action ?


- Register an event.


- Invoke the event and pass parameters


- Event will then trigger the script action and it will work as async process.


Interesting suggestion - I shall look into doing this.


Great, let me know if this helps.


damianfell
Tera Guru

Thanks Rahul - I did get it to work eventually, the main issue I kept hitting was that whilst the event was triggered by the business rule, when triggered by a delete transaction the script action wouldn't run.



After some experimentation it turns out that if you want an event trigger a script action from an event fired by a delete transaction, you need to over-ride the default action of including the record id of the source table in the event, otherwise the script action will halt when it evaluates that to a record that no longer exists (even though the action doesn't require that record detail).



So although the ServiceNow documentation suggests that the following will work, and fire an event:



gs.eventQueue("CI_Relationship.Change", current , current.child);



If you want that event to trigger a script action following a delete transaction, then you need to set the reference record to null:



gs.eventQueue("CI_Relationship.Change", null , current.child);



Hopefully if anyone else hits this issue, then this post will be useful.