current not available in script action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2016 08:16 AM
Hello Community
I'm working with a script action to respond to an event I have being triggered in the system. As I understand it from reading the wiki → Script Actions - ServiceNow Wiki � the script action already has knowledge of what current is. In my script action, i have gs.log("Current : " + current) and gs.log("Current ID : " + current.sys_id) and both are showing undefined in the logs. Any idea why current doesn't work here?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2016 08:43 AM
There you go, I think current is only available when triggering event form a business rule. Because script include does not run against any record, so current is not defined.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2016 08:47 AM
It appears you are expecting current to be the same as the record that triggered the event (e.g. incident.) It is not.
Do something like this, change your event to pass the table name and sys_id of the record you want..
gs.eventQueue('custom.err', current, current.sys_class_name, current.sys_id);
in your script action, add these lines to the top.
var myRec = new GlideRecord(event.parm1);
if (myRec.get(event.parm2)) {
// Do the rest of your code here using 'myRec' instead of 'current'
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2016 08:21 AM
Hi Kenneth,
That's odd. What release of ServiceNow are you using?
I'll assume since the script action is triggered, that you've already registered your event, correct? Current in a script action refers to the event that triggered it so it's generally not of much use to most people. Is it critical that you have current (event) information in your script action or were you looking for incident, user, or some other record information? For that, you'll need to do a GlideRecord query (which the event parameters are useful for passing a sys_id.)
Reference:
Event Registry - ServiceNow Wiki
Script Actions - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2016 08:33 AM