why i am getting sys_id instead of Display value in script include from client script?

Ramu6
Tera Contributor

Hi All

 

Actually i am writing client script and one choice field and one reference field as parameters into the script include but it gets sys_id instead of Display name

 

Client script

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
   // var userId =  g_form.getValue('requested_for').toString();
  // var category = g_form.getValue('u_leave_category');
    var gr = new GlideAjax('leavebalanceinfo');
 
    gr.addParam('sysparm_name', 'leaveinfo');
 
    gr.addParam('sysparm_type', g_form.getValue('u_leave_category'));
    gr.addParam('sysparm_user', g_form.getValue('requested_for'));
 
    gr.getXML(validation);
 
    function validation(response) {
 
var answer = response.responseXML.documentElement.getAttribute("answer");
//g_form.addInfoMessage(gs.getMessage("User's remaining balance is ") + answer);
if(answer)
alert(answer);
 
           g_form.showFieldMsg('u_leave_category','This is your current leave balance :'+answer, 'info');
 
 
 
Script include
 

var leavebalanceinfo = Class.create();
leavebalanceinfo.prototype = Object.extendsObject(AbstractAjaxProcessor, {
leaveinfo: function() {
var type = this.getParameter('sysparm_type');
gs.log("Type of leave is " + type); // here getting sys_id
var user = this.getParameter('sysparm_user');
gs.log("User is " + user); // Here also

var leave = new GlideRecord('u_yearly_leave');

leave.addQuery('assigned_to.sys_id', user);

leave.query();

gs.info("Query is " + leave.getEncodedQuery());

if (leave.next()) {

var time = new GlideRecord('u_leave_type_configuration');
time.addQuery('u_time_card_category.sys_id', type);
time.query();
if (time.next()) {


gs.info("Found leave record " + leave.getDisplayValue());
gs.info("User's remaining balance is " + leave.getValue('u_remaining_leave_days'));
return leave.getValue('u_remaining_leave_days');
}
}

gs.info("No record found");

},
type: 'leavebalanceinfo'
});

 
Please help me to sort this 
 
Thanks
Ram
 

 

4 REPLIES 4

Ravi_shrestha
Tera Contributor

By using getDisplayValue() instead of getValue(), you should be able to retrieve the display names of your choice and reference fields in the client script and script include.

swathisarang98
Giga Sage
Giga Sage

Hi @Ramu6 ,

 

Try using leave.getValue('u_remaining_leave_days').toString(); and if it doesn't work can you let me know which type of field u_remaining_leave_days is and can you give screen shots of all the info what you are getting ?

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

Nishi4
Tera Contributor

change this to return leave.getDisplayValue('u_remaining_leave_days');

SunilKumar_P
Giga Sage

Hi @Ramu6, what is the type of u_remaining_leave_days field? if it is of reference type then it returns the sys_id of that record. Can you try the getDisplayValue method as suggested by other community members and let us know?

 

Regards,

Sunil