why i am getting sys_id instead of Display value in script include from client script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 02:24 AM
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
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'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 02:37 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 03:34 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 03:41 AM
change this to return leave.getDisplayValue('u_remaining_leave_days');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 03:48 AM
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