Retrieve variable data from a reference variable in a catalog client script

donnadavis
Tera Expert

I have a catalog item that includes a reference variable that is a list of all open onboarding request items. The user selects the request item they want to cancel.  I want to display some of the data from the request item after the selection is made.  I can select the fields that are part of the request item such as short description and due date, but I cannot figure out how to include some of the variable data such as employee termination date.  I have code in a catalog client script that returns short description and due date, but employee termination date comes back as undefined.  What do I do to retrieve the variable information?  This is my code.  I have tried 2 different ways to retrieve the term date.  Thanks for your help.

function onChange(control, oldValue, newValue, isLoading) {

if (isLoading || newValue == '') {

return;

}

                var reqRITM = g_form.getReference("see_open_items", setValues);

               

                function setValues(reqRITM){

                g_form.setValue(open_short_description', reqRITM.short_description);

                g_form.setValue(open_due_date', reqRITM.due_date);

g_form.setValue(open_term_date', reqRITM.term_date);

//also tried g_form.setValue(open_term_date', reqRITM.variables.term_date);

                }

}

1 ACCEPTED SOLUTION

Mike Patel
Tera Sage

You will have to use GlideAjax instead of getRef.

Refer to my article and you can do something similar with sc_req_item table.

https://community.servicenow.com/community?id=community_article&sys_id=67cdfcd3db4c985c2be0a851ca961...

View solution in original post

2 REPLIES 2

Mike Patel
Tera Sage

You will have to use GlideAjax instead of getRef.

Refer to my article and you can do something similar with sc_req_item table.

https://community.servicenow.com/community?id=community_article&sys_id=67cdfcd3db4c985c2be0a851ca961...

Michael Jones -
Giga Sage

Get Reference won't return fields like variables, which are not on the actual record itself. You would need to use an GlideAjax call to send a request to the server and use a GlideRecord call to query the data and return it client-side. 

As a tip, you can get the variable data by passing the sys_id of the RITM to your GlideAjax and doing a query something like this:

var sysID = '<your_ritm_sys_id>';
var RITM = new GlideRecord('sc_req_item');
RITM.get(sysID);
//Then you can access variables like this:
var term_date = RITM.varables.open_term_date;

Here are some GlideAjax examples:

https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/script/server_scripting/reference...

Hope this helps!

If this was helpful or correct, please be kind and click appropriately!

Michael Jones - Proud member of the CloudPires Team!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!