Client Script To Get Catalog Tasks For A RITM

Neil Santucci
Tera Contributor

Hi,

 

I'm trying to get the catalog tasks related to a request in a client script

 

var ritmID = g_form.getUniqueValue();
try {
    var scTaskGr = new GlideRecord('sc_task');
    scTaskGr.addQuery('request_item=' + ritmID);
    scTaskGr.query();

    while (scTaskGr.next()) {
        alert(scTaskGr.sys_id && " " && scTaskGr.short_description);
    }
}
catch(err)
{
    alert(err.message);
}
 
It sort of works - catalog tasks are returned but all catalog tasks, not just for the ritm specified. I'm pretty sure I'm missing something really obvious but can't figure it out. If anyone has any suggestions that would be great.
 
thanks
Neil
1 ACCEPTED SOLUTION

HrishabhKumar
Kilo Sage

Hi @Neil Santucci ,

You are using wrong syntax in addQuery part, you need to remove the + sign or use addEncodedQuery instead and your syntax in alert is also wrong. I've added the code with improved syntax below:

var ritmID = g_form.getUniqueValue();
try {
    var scTaskGr = new GlideRecord('sc_task');
    scTaskGr.addQuery('request_item', ritmID); // Use addQuery with two arguments
    scTaskGr.query();

    while (scTaskGr.next()) {
        alert(scTaskGr.sys_id + " " + scTaskGr.short_description); // Use + for concatenation
    }
}
catch(err) {
    alert(err.message);
}

 

Thanks,

Hope this helps.

If my response proves helpful please mark it helpful and accept it as solution to close this thread.😊

 

View solution in original post

3 REPLIES 3

HrishabhKumar
Kilo Sage

Hi @Neil Santucci ,

You are using wrong syntax in addQuery part, you need to remove the + sign or use addEncodedQuery instead and your syntax in alert is also wrong. I've added the code with improved syntax below:

var ritmID = g_form.getUniqueValue();
try {
    var scTaskGr = new GlideRecord('sc_task');
    scTaskGr.addQuery('request_item', ritmID); // Use addQuery with two arguments
    scTaskGr.query();

    while (scTaskGr.next()) {
        alert(scTaskGr.sys_id + " " + scTaskGr.short_description); // Use + for concatenation
    }
}
catch(err) {
    alert(err.message);
}

 

Thanks,

Hope this helps.

If my response proves helpful please mark it helpful and accept it as solution to close this thread.😊

 

thanks HrishabhKumar, that works, knew it'd be something simple. Thanks for your help

Hi HrishabhKumar,

 

I'm hoping that you can help with a follow up question. I got the code you provided working client side in the Core UI, next I need to do the same for Service Operations Workspace. The code runs but it doesn't return any catalog tasks and no errors either. Any ideas?

 

Thanks

Neil