To get Value of LOOKUP SELECT BOX field

akhila13
Tera Expert

I have created a variable set 'facility' and inside that a variable named 'building'.. Variable building is of type LOOKUP SELECT box.. i want to map the value in field building to description field in RITM...

25 REPLIES 25

Look up value field will only return a single field information. If you would like to populate description field with both name and location then you need to use GlideAjax

Could you help me with GlideAjax code

Here are the scripts

Update the look up value field back to sys_id and try the below scripts

You might need to the formating while setting in the description field

Client script

var ga = new GlideAjax('GetBuildingInfo');
	ga.addParam('sysparm_name','getInfo');
	ga.addParam('sysparm_Building_id', g_form.getValue('building'));
	ga.getXML(builInfo);
	
	function builInfo(response) {
		
		var answer = response.responseXML.documentElement.getAttribute("answer");
		
		
			g_form.setValue('description', JSON.stringify(answer));
		
	}

Script Include

Name:GetBuildingInfo

Client callable: true

var GetBuildingInfo = Class.create();
GetBuildingInfo.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	getInfo: function() {
		var dat = this.getParameter('sysparm_Building_id');
		
		var gr = new GlideRecord("YOUR_TABLE_NAME");
		gr.addQuery("sys_id", "IN", dat);
		gr.query();
		var arr=[];
		while (gr.next()) {
			var obj = {};
			obj.name = gr.name.toString();
			obj.location = gr.location.getDisplayValue();
			arr.push(obj);
		}

		return new JSON().encode(arr);
	},
	
    type: 'GetBuildingInfo'
});

tried this.. but not working 😞

Is the table name updated in script include?

Also, can you put an alert statement in client script and see what value is it returning for JSON.stringify(answer)