how to get original value instead of sys id
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2020 04:01 AM
Hi,
I am using getReference on catalog client script and also getting value fine but one of value i am getting is sys id but i want its text value ie display value not sys id . i use getDisplayValue() or display box but nothing is working
code look like..
var caller = g_form.getReference("variables.user",callback);
function callback(caller){
var location = caller.location;// getting sys id
// Need to change this sys id into display value format
g_form.setValue("variables.location",location);
}
Thanks in advance

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2020 04:54 AM
Following will get Incident's caller username in field 'username'.
I have client script on reference field to incident table. Change the table and field to those that's needed in your script.
Client Script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ajax = new GlideAjax('GetCallerUserNameFromIncident');
ajax.addParam('sysparm_name', 'getUserName');
ajax.addParam('sysparm_incident_id', newValue);
ajax.getXMLAnswer(function(answer) {
if (answer.length > 0) {
g_form.setValue('username', answer);
}
});
}
Script Include:
var GetCallerUserNameFromIncident = Class.create();
GetCallerUserNameFromIncident.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserName: function() {
var incident_id = this.getParameter('sysparm_incident_id');
var grIncident = new GlideRecord('incident');
if (grIncident.get(incident_id)) {
var grUser = new GlideRecord('sys_user');
if (grUser.get(grIncident.caller_id)) {
return grUser.name;
} else {
return '';
}
} else {
return '';
}
},
type: 'GetCallerUserNameFromIncident'
});