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

Abhinay Erra
Giga Sage

Did you schedule an event? Can you share your script


var json = new JSON();


var parameterOne = (isJSON(event.parm1) == true) ? json.decode(event.parm1) : event.parm1;


createIncident(parameterOne);


gs.log("CURRENT : " + current.sys_id + " - " + current.number);



var recordTextHeader = "Record Information\n";


      var tableName = "Table : Unable to determine the source table.\n";




  if(current.sys_class_name != ""){


  tableName = "Table : " + current.sys_class_name + "\n";


  }


      var recordNumber = "Number : Unable to determine record number.\n";


  if(current.number != ""){


  recordNumber = "Number : " + current.number.toString() + "\n";


  }


      var uniqueID = "Unique ID : Unable to determine the sys_id of the source record.\n";


      if(current.sys_id != ""){


              uniqueID = "Unique ID : " + current.sys_id.toString() + "\n";


      }


      var item = "Item : Unable to determine what item was requested.\n";


      if(current.sys_class_name == "sc_req_item"){


              if(!current.cat_item.nil()){


                      item = current.cat_item.getDisplayValue() + "\n";


              }


      }



If by schedule an event, you mean register an event, yes I have.


find_real_file.png


"custom.error"   should be scheduled in a business rule? Did you schedule this event in a business rule on a table?


I'm not sure I follow what you mean by "scheduling" the event. I'm calling the event from a script include where I'm looping through some user records. If, during that loop, I detect a duplicate record, I trigger my event. Which in turn, I would expect to trigger my Script Action. Can you elaborate on what you mean by "schedule" the event?