GlideappVariablePoolQuestionSet not returning all variables question and values

Waseem4
Tera Expert

Hi, 

I have an issue with a scripted rest api which uses GlideappVariablePoolQuestionset to return all variable data. 

The purpose of this rest api is to allow external users to call this api (passing in sctask number via query params) which will return all populated variables questions and answers. 

Unfortunately this does not return all the populated variables and values. Please see below for the scripted rest api. 

From the screen shot you can see the variables have been populated but it does not return the data. For some variables it does return but for other it does not.

 

Any help will be appreciated.

 

 

 

(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {

// implement resource here
var parent_result = [];
var item_variable = [];
var obj = {};
var variableName="";
var params = request.queryParams;
var tsk_num = params.sc_task_sys_id.toString();
var usrname = gs.getProperty("CatalogTaskScriptedAPIUser");
var psswrd = gs.getProperty("CatalogTaskScriptedAPIUsrPass");
var endpt = gs.getProperty("CatalogTaskScriptedAPIEndpt");
var req = new sn_ws.RESTMessageV2();
req.setHttpMethod('get');
req.setBasicAuth(usrname.toString(), psswrd.toString());
req.setEndpoint(endpt.toString());

req.setQueryParameter("sysparm_query", "number=" + tsk_num);
req.setQueryParameter("sysparm_display_value", "all");

var resp = req.execute();
var resp_bod = resp.getBody();
var sctsk = new GlideRecord("sc_task");
sctsk.addQuery("number", tsk_num);
sctsk.query();
if (sctsk.next()) {
var i = 0;
var grRitm = new GlideRecord("sc_req_item");
grRitm.addQuery("sys_id", sctsk.request_item);
grRitm.query();
if (grRitm.next()) {
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(grRitm.sys_id); // requested item sys_id
set.load();

var vs = set.getFlatQuestions();

for (var i = 0; i < vs.size(); i++) {
var vname = vs.get(i).getLabel();
obj[vname] = {
"display_value": vs.get(i).getDisplayValue(),
"value": vs.get(i).getValue().toString()

};


}
var mRow = new global.GetMultiRowJsonforSCTaskAPI();
var mRowVal = mRow.intit(sctsk.request_item);
if(mRowVal!=JSON.stringify({}))
obj["MultiRow"]=JSON.parse(mRowVal);
}

}
//return result;
parent_result.push(JSON.parse(resp_bod));
parent_result.push(obj);
//if(mRowVal)
//parent_result.push(JSON.parse(mRowVal));
return parent_result;
})(request, response);

 

 

find_real_file.png

 

find_real_file.png

1 ACCEPTED SOLUTION

Waseem4
Tera Expert

Issue is now resolved. I had to add an if condition to look for only populated display values. 

            var set = new GlideappVariablePoolQuestionSet();
			set.setRequestID(grRitm.sys_id); // requested item sys_id
			set.setTaskID(grRitm.sys_id);
			set.load();

			var vs = set.getFlatQuestions();

			for (var i = 0; i < vs.size(); i++) {
				var vname = vs.get(i).getLabel().toString();
			if(vs.get(i).getDisplayValue() != '') {
				obj[vname] = {
					"display_value": vs.get(i).getDisplayValue(),
					"value": vs.get(i).getValue().toString()
					
				};

View solution in original post

11 REPLIES 11

Allen Andreas
Administrator
Administrator

Hello,

Please use the appropriate forum feature: "Insert/Edit code sample" when pasting code on these forums. This helps keep things organized and easier to read:

find_real_file.png

Also, please try and paste your screenshots directly into your post otherwise you're having us download your files. Most don't like to do that. I particularly don't as I help hundreds of people per year and that would take up a lot of space on my computer.

Please mark reply as Helpful, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

vkachineni
Kilo Sage
Kilo Sage

One of my code snippets has taskID. can you add that line with your variables and test.

var set = new GlideappVariablePoolQuestionSet();  
set.setRequestID(item.sys_id);  
set.setTaskID(current.sys_id);  
set.load();  
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

Hi, 

 

Thanks for the reply. I have added the taskID line but unfortunately this did not work. 

in a background script window can you run this code to see if your RITM returns values

 

var set = new GlideappVariablePoolQuestionSet();
set.setRequestID('dd73d7b3db6b8010868370e239961980'); //put your RITM sys id
set.load();
var vs = set.getFlatQuestions();
for (var i = 0; i < vs.size(); i++) {    
    gs.print(vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue());
}

/*
OOB for RITM0010028
*** Script: CPU Speed = Intel Xeon Processor (2.66GHz 1.333GHz FSB)
*** Script: Memory = 1GB
*** Script: Hard Drive = 250GB
*** Script: Operating System = Windows XP Professional
*** Script: Special Requirements = testing

*/
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022