how to get RITM variables in Client callable script include, I am attaching the picture of code

Chandu14
Tera Contributor

how to get RITM variables in Client callable script include, I am attaching the picture of code.

 

get_Request_Details: function() {
var array = [];
var bsid = this.getParameter('sysparm_sys_id');
var gr = new GlideRecord('sc_req_item');
gr.addQuery('sys_id', bsid);
gr.query();
gs.info("CHECK <<<<< 00:" + bsid);
if (gr.next()) {
var ff = gr.number;
var gf = gr.type;

var obj = {

type: gr.variables.type,

employee_type: gr.variables.employee_type,
report_to: gr.variables.report_to,
direct_reports: gr.variables.direct_reports,
preferred_first_name: gr.variables.preferred_first_name,
legal_name: gr.variables.legal_name,
work_in_location: gr.variables.work_in_location,
state_name: gr.variables.state_name,
};
}
array.push(obj);
gs.info("CHECK <<<<< :" + JSON.stringify(array) + "OBJ" + JSON.stringify(obj) +"<<<< "+ ff +"<<<< "+ gf);

 

 

 

I am gettiing the array object as empty log as mentioned below

[{"type":{},"report_to":{},"direct_reports":{},"preferred_first_name":{},"legal_name":{},"work_in_location":{},"state_name":{}}]OBJ{"type":{},"report_to":{},"direct_reports":{},"preferred_first_name":{},"legal_name":{},"work_in_location":{},"state_name":{}}

7 REPLIES 7

Aman Kumar S
Kilo Patron

Code looks fine, its just that why don't you declare obj outside if condition, and assign values inside if.

Best Regards
Aman Kumar

Hi Aman,

Its not working 

 

jalex1351
Tera Contributor

Greetings! This is a bit of an old thread, but I have seen this issue before and came up with a solution that helped me.

I created a function in a script include gave me the value I was seeking since "ritm_GR.variables.<variable_name>" was returning empty braces.

 

I built the function, but I found the information from somewhere on Google.

 

Function Name: getRITMVariableValue

Param 1: ritm_sysid > The sys_id of a RITM record (sc_req_item) as a string value.

Param 2: variableName > A string name value of a variable from a catalog item.

 

getRITMVariableValue: function(ritm_sysid, variableName) {
        if (gs.nil(ritm_sysid) || gs.nil(variableName)) {
            throw new "Error retrieving variable value";
        }

        var set = new GlideappVariablePoolQuestionSet();
        set.setRequestID(ritm_sysid);
        set.load();

        var vs = set.getFlatQuestions();

        for (var i = 0; i < vs.size(); i++) {
            if (vs.get(i).getName() == variableName) {
                return vs.get(i).getDisplayValue();
            }
        }

        return "";
    }