The CreatorCon Call for Content is officially open! Get started here.

How to access catalog item variable in Scheduled job (Job type - Scheduled Script Execution)

nithyamaruthu
Tera Expert

This is my query. In this tracking_no_computer is a variable from a variable set. Now my script returns trckNum= Undefined. How to access this variable in my scheduled job.

Please help.

var queryString ='active=true^short_descriptionLIKE(Refresh)^assignment_group=e8a1b4646f79d90067cf09c54b3ee407';

var sct = new GlideRecord('sc_task');

sct.addEncodedQuery(queryString);

sct.query();

while (sct.next()){

{

var trckNum=sct.variables.tracking_no_computer;

gs.log("This is   Fedex info message"+trckNum);

if(trckNum != '')

{

f.track(trckNum);

sct.variables.u_tracking_status_field = f.status;

sct.update();

}

}

1 ACCEPTED SOLUTION

larstange
Mega Sage

Hi



As far as I remember the variable is not directly available on the sc_task. You need to create another gliderecord and fetch the requested item, that the task belongs to. Then you can acces the variable through that.



You might also be able to access to through "sct.request_item.variables.u_tracking_status_field"


View solution in original post

7 REPLIES 7

larstange
Mega Sage

Hi



As far as I remember the variable is not directly available on the sc_task. You need to create another gliderecord and fetch the requested item, that the task belongs to. Then you can acces the variable through that.



You might also be able to access to through "sct.request_item.variables.u_tracking_status_field"


Thanks for your reply. But it is not a requested item variable. It is a variable inside a variable set.


Ankur Bawiskar
Tera Patron
Tera Patron

Hi Maruthu,



That variable is on RITM table and not on sc_task so I updated the code.


"sc_task" has request_item field which refers to RITM table so you need to fetch using that field.



var queryString ='active=true^short_descriptionLIKE(Refresh)^assignment_group=e8a1b4646f79d90067cf09c54b3ee407';


var sct = new GlideRecord('sc_task');


sct.addEncodedQuery(queryString);


sct.query();



while (sct.next()){


{


var trckNum = sct.request_item.variables.tracking_no_computer;   // updated the code



gs.log("This is   Fedex info message"+trckNum);



if(trckNum != '')


{


f.track(trckNum);


sct.variables.u_tracking_status_field = f.status;


sct.update();


}


}



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thanks for your reply. But it is not a requested item variable. It is a variable inside a variable set.