current not available in script action

Ken83
Mega Guru

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?

8 REPLIES 8

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.


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'


}


Chuck Tomasi
Tera Patron

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


Yes, I have the event registered. I'm using Eureka...


find_real_file.png



You might have actually hit a point for me. I am looking for information about the record that was submitted when the event was triggered. That's what I was looking to pull from current.