you can use below script to get the name of the variable. 

 

var set = new GlideappVariablePoolQuestionSet();
			set.setRequestID(current.sys_id);
			set.load();
			var vs = set.getFlatQuestions();
			for (var i = 0; i < vs.size(); i++) {
				if (vs.get(i).getDisplayValue() != '' && +vs.get(i).getLabel() != '') {
					
					gs.log("\n" + '<b>' +vs.get(i).getLabel() + " = " + '</b>' + vs.get(i).getDisplayValue() + "\n");
				}
			}

 

 

Reference: 

https://jace.pro/post/2017-09-30-undocumented-scripts/

if you have stored ritm sys_id in empSysID then replace current.sys_id to empSysID

@shaik.irfan 

you can use this script to get the question name

If you are having 2 variables

1) requested_user - value is Abel Tuter

2) my_choice - value is Adobe Photoshop

Output would be something like this

[{"name":"requested_user","value":"Abel Tuter"},{"name":"my_choice","value":"Adobe Photoshop"}]

var arr = [];

var gr = new GlideRecord('sc_req_item');
if (gr.get(empSysID)) {
    var variables = gr.variables.getElements();
    for (var i=0;i<variables.length;i++) {
        var question = variables[i].getQuestion();

var obj = {};

obj["name"] = question.getName().toString();
obj["value"] = question.getDisplayValue();
arr.push(obj);
    }
}    

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

@shaik.irfan

Hope you are doing good.

Did my reply answer your question?

If so, please mark it correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.

Thanks!
Ankur

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

I have similar requirement, The above solution works for me except for attachment type variable.

When I try to fetch attachment variable value its returns null, though the attachment is available in sys_attachment table

Does SN store the mapping of attachment variable and attachment in any table?