User details showing sys id's
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2023 07:16 AM
Hello,
I created 2 variables 1.Requested For(Reference to user table),2.Reason(Single line text).I want to requested for details like email,department,manager,location... for that i wrote on change catalog client script but the problem here is location,manager,department showing sys id's.Please help me.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//function onChangeRequestedFor() {
var requestedForSysID = g_form.getValue('requested_for');
if (requestedForSysID) {
// Get the 'Requested For' user record
var grRequestedFor = new GlideRecord('sys_user');
if (grRequestedFor.get(requestedForSysID)) {
// Get the 'Requested For' user's email and department
var email = grRequestedFor.email;
var loc = grRequestedFor.location;
var mans = grRequestedFor.manager;
// Set the email and department values in the 'Reason' field
g_form.setValue('reason', 'Requested For Email: ' + email + 'Department: ' + loc + 'Manager: ' + mans);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2023 07:22 AM - edited ‎07-24-2023 07:23 AM
After line var grRequestedFor = new GlideRecord('sys_user');
Add this :-
grRequestedFor.addQuery('caller_id',requestedForSysID);
grRequestedFor.query();
Replace If statement line by this :-
if(grRequestedFor.next()){
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2023 07:57 AM
It is not working.and i have a doubt should we use Glide Record methods in on Change client scripts?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2023 07:23 AM
Hello @Shaik22
Simple solution would be to change the type of the fields to reference with their respective tables.
location referring to location table cmn_location
manager referring to user table sys_user
department referring to Department table cmn_department
Thank you,
Ali
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2023 11:25 PM
Hi @Shaik22 ,
You should not use Glide record in catlog client script.
alternate method is of script include and client script.
Script include client callable:
var CheckRecords = Class.create();
CheckRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkRecordPresent: function(){
var obj = {};
var id = this.getParameter('sysparm_userID');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', id);
gr.query();
if(gr.next()){
obj['email'] = gr.getDisplayValue('email');
obj['manager'] = gr.getDisplayValue('manager');
obj['location'] = gr.getDisplayValue('location');
}
return JSON.stringify(obj);
},
type: 'CheckRecords'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('CheckRecords');
ga.addParam('sysparm_name', "checkRecordPresent");
ga.addParam('sysparm_userID', g_form.getValue('requested_for')); // give here your variable name
ga.getXMLAnswer(function(answer){
if(answer != 'not found'){
var parser = JSON.parse(answer);
g_form.setValue('reason', 'Requested For Email: ' + parser.email + 'Department: ' + parser.location + 'Manager: ' +parser.manager);
}
});
//Type appropriate comment here, and begin script below
}
Thanks and Regards,
Rahul