How to variable name and value in script include

shaik_irfan
Tera Guru

Hi,

 

in the script include i am trying to get the variable details

 

When below code i am able to get the variables values but not the name

 

var user = new GlideRecord('sc_req_item');
		user.addQuery('sys_id', empSysID);
		user.query();
		if(user.next())
		{	
			
			obj.add = user.variables.software_requirements.getValue();
			obj.value = user.variables.value.getValue();
		
			arr.push(obj);
		}

gs.eventQueue('notify.variables', current, arr); // I am trying to send the values to send as email
1 ACCEPTED SOLUTION

@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  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

11 REPLIES 11

@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  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@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  ||  9x 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?

@Jidesh 

Can you post a new question and tag me in that question?

This question is quite older.

Regards
Ankur

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

@shaik.irfan 

Hope you are doing good.

Let me know if I have answered your question.

If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.

If not, please let us know if you need some more assistance.

Regards
Ankur

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