Events that refer to deleted records, don't seem to work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2017 10:58 AM
I'm working through the "Module: Events and script actions" part of the "Coding on ServiceNow" self-paced tutorials.
I have a business rule that fires events whenever an "attendee" record is added to the database, changed, or removed. The business rule and the events are tied to the attendee table. The business rule fires after insert, update, or delete.
The script action that In the script action that gets triggered for adds, seems to work. (It sets about to counting up some related information, and modifying a table with the result.)
The one that handles deletes, doesn't. It flat out doesn't seem to run (i.e. even my log messages don't show up), and instead, I get messages like "getEventTarget() called with invalid record reference ... could have been deleted".
Well, yes, the record was deleted. That's kind of the point. 🙂 A record was deleted, and now I need to act on that deletion (by updating a count that will get stored into another table). Though this is just a warning message, it seems to cause my script action to abort, as I've got a gs.info() call right at the top that never shows up in the log.
I've scoured Google for answers, but I see none.
I tried to work around this by splitting out the logic (supplied by the tutorial, mind you; I didn't come up with this stuff) so that the delete portion is triggered by a second business rule that fires before the record is deleted. Because the events are handled asynchronously (it seems), it didn't make much difference because the record was still gone by the time the script action kicked in.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2017 09:52 AM
That's actually exactly what I've got (per the instructions in the tutorial), at least as the first part of the logic/flow. The business rule is set to run after any insert, update, or delete. Though (again, per the instructions in the tutorial), all the business rule does is queue up some events, so that script actions (that run later, asynchronously) can do some bookkeeping.
At the point in time where the events are queued (via gs.eventQueue), I do have access to "current" and "previous". When I pass these as arguments to the event, though, in cases where I've deleted a record, the script action that's set to fire as a result of these events never seems to run. I now expect the warning I get ("getEventTarget() called with invalid record reference ... could have been deleted"), based on your first response. Since it's just a warning, though, I wouldn't expect the script action to fail to run.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2017 08:33 AM
Just wanted to add that I had the exact same issue and concern going through the exact same SN tutorial:
https://developer.servicenow.com/app.do#!/training/article/app_store_learn_coding_istanbul_c_Module8... https://developer.servicenow.com/app.do#!/training/article/app_store_learn_coding_istanbul_c_Module8...
This led to the same hours spent troubleshooting why the "Attendee Delete Action" wasn't executing during an attendee delete. I suppose it was valuable from a troubleshooting perspective and to become familiar with the event and error logs but is ultimately frustrating that the product documentation/training causes this "issue" to occur.
Thank you to this thread and the above suggestion to pass "null" for the GlideRecord reference where the tutorial was referencing "current". With that change I was able to proceed and get the delete script action to work.
Tutorial code:
gs.eventQueue('x_snc_marketing_ev.attendee.deleted', current, current.marketing_event, current.email);
Changed to:
gs.eventQueue('x_snc_marketing_ev.attendee.deleted', null, current.marketing_event, current.email);