Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

how to get original value instead of sys id

Vikram Meena
Giga Contributor

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

10 REPLIES 10

Hitoshi Ozawa
Giga Sage
Giga Sage

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'
});