Client Side Code Works In Core UI But Not Service Operations Workspace

Neil Santucci
Tera Contributor

Hi,

 

I've written this client side code in the Core UI to get all the tasks of the current RITM. 

 

var ritmID = g_form.getUniqueValue();
//var querytext = "request_item=" + ritmID;

 

try {

     var scTaskGr = new GlideRecord('sc_task');
     scTaskGr.addQuery('request_item', ritmID); 
     //scTaskGr.addEncodeQuery(querytext);
     scTaskGr.query();

     while (scTaskGr.next()) {
          //Update catalog tasks
     }

}
catch(err)
{
     alert(err.message);
}

 

When I try to use it in SOW nothing happens. It doesn't throw an error, just doesn't return any catalog tasks. I've tried using scTaskGr.addEncodeQuery(querytext); (commented out in the code above) but addEncodeQuery and addEncodedQuery throw an error as unrecognised functions.

 

If anyone has any suggestions as to where I'm going wrong that would be very helpful.

 

thanks

Neil

8 REPLIES 8

Anurag Tripathi
Mega Patron
Mega Patron

Hi Neil,

 

Firstly, its not a good practice to use GlideRecord on Client side script. You should use GlideAjax instead and call a script include.

 

For your script, can you confirm that the ui type field is set to ALL and Global is checked?

-Anurag

Hi Anurag, 

I'm fairly new to scripting in ServiceNow and was basing this on what has already been written but since then I've realised that using GlideAjax and script includes is a better approach. I'd rather not do that now as I've already got code that should be working and I don't really have the time to be implementing something new. This function isn't going to be used all that often so performance is less of a concern than it might be otherwise.

 

Wasn't sure what you meant by "can you confirm that the ui type field is set to ALL and Global is checked", it's getting the catalog tasks that I'm struggling with.

 

thanks

Neil

Hey,

No worries, when I respond here I try give you all the information so i mentioned the best practice.

This is what I mean,

Check these fields on your client script

AnuragTripathi_1-1720605049507.png

 

-Anurag

it's not a client side script, it's in a UI action on the sc_req_item table