Fetch Value of Lookup select box?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2021 02:39 AM
I have requirement to fetch the variable value which is of Lookup select box.
The variable is declared as:
Now as we see its Lookup field value is Sysid rather than country so if i write a client script as follow:
Can anyone help me in how to get the value of this field as i need to this value to update sys_user table?
Regards,
Sneha
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2021 02:41 AM
Hi,
Please use below code
g_form.getValue('variables.country');
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2021 06:45 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2021 06:06 AM
To get the Display Value in Client Side you need to use below syntax:
g_form.getDisplayBox('variables.country').value;
Or you can use G-form.getReference method as well with a callback function defined as explained below:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue) {
var getRITM = g_form.getReference('requested_item', getRITMDetails);
}
function getRITMDetails(details) {
g_form.setValue('number', details.number); //Replace number with Display Name of the field you want.
}
//Type appropriate comment here, and begin script below
}
Or if above syntax does not works then you can also use GLideAjax as well and make a Server call to get the Display Value . Below is an sample example on how to useGlideAjax:
Client Side:
var ga = new GlideAjax('Script Include Name');
ga.addParam('sysparm_name', 'Function Name Defined In Script Incldue');
ga.addParam('sysparm_buildingid', g_form.getValue("variables.country"));
ga.getXML(getResults);
}
function getResults(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
Now based on Answer you can set what you want where answer is the Display Value returned from Script Incldue
}
Script Include:
var ScriptIncludeName = Class.create();
ScriptIncludeName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getResult: function () {
var buildingid = this.getParameter('sysparm_buildingid');
var loc = new GlideRecord('cmn_location');
if (loc.get(buildingid)) {
var campus = new GlideRecord('cmn_location');
if (campus.get(loc.parent)){
var json = new JSON();
var results = {
"sys_id": campus.getValue("sys_id"),
"name": campus.getValue("name")
};
return json.encode(results);
}
} else {
return null;
}
}
});
Just an sample code, you can modify it as needed or let me know your detailed requirement, I can modify and share the updated code with you.
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke