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

Yashsvi
Kilo Sage

Hi @Neil Santucci,

please check below script:

var ritmID = g_form.getUniqueValue();

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

    // Logging number of records found
    gs.info("Number of sc_task records found for RITM " + ritmID + ": " + scTaskGr.getRowCount());

    while (scTaskGr.next()) {
        // Process each sc_task record
        var taskID = scTaskGr.getValue('sys_id');
        var taskName = scTaskGr.getValue('short_description');
        // Add your logic to update catalog tasks here
        gs.info("Found sc_task record: " + taskID + " - " + taskName);
    }
}
catch(err) {
    gs.error("Error retrieving sc_task records: " + err.message);
    alert("Error retrieving sc_task records: " + err.message);
}

Thank you, please make helpful if you accept the solution.

Hi Yashsvi, getting zero tasks returned (and there is one associated task)

Hi @Neil Santucci,

  • Verify RITM ID: Ensure ritmID captures the correct Requested Item ID (g_form.getUniqueValue() should be in the right context).

  • Check Table and Field Names: Confirm sc_task table and request_item field names are correct.

Check below script also:

 

var ritmID = g_form.getUniqueValue();

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

    // Logging number of records found
    gs.info("Number of sc_task records found for RITM " + ritmID + ": " + scTaskGr.getRowCount());

    while (scTaskGr.next()) {
        // Process each sc_task record
        var taskID = scTaskGr.getValue('sys_id');
        var taskName = scTaskGr.getValue('short_description');
        // Add your logic to update catalog tasks here
        gs.info("Found sc_task record: " + taskID + " - " + taskName);
    }
}
catch(err) {
    gs.error("Error retrieving sc_task records: " + err.message);
    alert("Error retrieving sc_task records: " + err.message);
}

 

Thank you, please make helpful if you accept the solution.

I checked the RITM ID and it's correct, the table and field names are correct as the work in the Core UI