Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

How to get the catalog task number associated with a requested item

suprakash
Giga Expert

for my requested item a catalog task is generated . I want to get the the task number which is present in in related list in my requested item form.How can i get it using background script

7 REPLIES 7

Correct me if I a wrong,Do you want to get the RITM sys_id from the GlideRecord. If it is yes below is the code the setting the limit for first 5 records.


var ritm=new GlideRecord('sc_req_item');


ritm.setLimit(5);


ritm.query();


while(ritm.next()){


var gr=new GlideRecord('sc_task');


gr.addQuery('request_item',ritm.sys_id);//provide the ritm sys_id


gr.query();


while(gr.next())


{


var res=gr.number+','+res;


}


gs.log(ritm.number+'-'+res);


}


define the variable res above the loop



instead of below lines


while(gr.next())


{


var res=gr.number+','+res;


}




use this



var res = '';


while(gr.next())


{


res =gr.number+','+res;


}


Uncle Rob
Kilo Patron

The problem is there isn't "THE".   sc_task has a many-to-one relationship with sc_req_item.   Via background script you can get ALL of a Requested Item's child SC_Tasks by...



var rotiserie_chicken =   (whatever the sys_id of your requested item);


var prostetnic_vogon_jeltz = new GlideRecord('sc_task');


prostetnic_vogon_jeltz.addQuery('parent', rotiserie_chicken);


prostetnic_vogon_jeltz.query();


while (prostetnic_vogon_jeltz.next())


  gs.print(prostetnic_vogon_jeltz.number + " - " + prostetnic_vogon_jeltz.short_description);


}


gs.print("Remember to like and mark correct!");


gs.print("Chuck Tomassi is the king");




Fun fact:   An sc_task populates both the request_item and parent fields with the RITM's sys_id.   I use Parent just for consistency across the platform.