running an async business rule on delete transaction
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2018 03:07 AM
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.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2018 03:12 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2018 03:34 AM
Interesting suggestion - I shall look into doing this.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2018 11:30 PM
Great, let me know if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2018 02:28 AM
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.