
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 04-13-2020 06:59 AM
I see lot of users are using GlideRecord in client script (Which is not recommended and it will not work on Service Portal) so you can stop using GlideRecord in client script and replace with GlideAJAX. Example below, you can add fields based on your requirement.
Create Script Includes;
Name: commonUtils
Client callable: true (checked)
Script:
var commonUtils = Class.create();
commonUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserInfo: function(){
var user = this.getParameter('sysparm_user');
var gr = new GlideRecord("sys_user");
gr.get(user);
var deptname = gr.department.getDisplayValue();
var dept = gr.getValue('department');
var manager = gr.getValue('manager');
var managername = gr.manager.getDisplayValue();
var location = gr.getValue('location');
var locationname = gr.location.getDisplayValue();
var response = {};
response.deptname = deptname;
response.dept = dept;
response.manager = manager;
response.managername = managername;
response.location = location;
response.locationname = locationname;
return JSON.stringify(response);
},
type: 'commonUtils'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// Call the GA function
var ga = new GlideAjax('commonUtils');
ga.addParam('sysparm_name', "getUserInfo");
ga.addParam('sysparm_user', newValue); //Onchange field is reference field to sys_user table
ga.getXMLAnswer(function(answer){
var response = JSON.parse(answer);
g_form.setValue('department_name', response.deptname); //used for string field
g_form.setValue('department', response.dept); //used for reference field to department table
g_form.setValue('manager_name', response.managername); //used for string field
g_form.setValue('manager', response.manager); //used for reference field to user table
g_form.setValue('location_name', response.locationname); //used for string field
g_form.setValue('location', response.location); //used for reference field to location table
});
}
- 12,960 Views

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Nice example of how easy it can be with GlideAjax and getXMLAnswer used. Instead of GlideRecord query or quick escape with getReference.
Maybe you do want to update the Client Script. If the fields/variables concerning department, manager, location are all of reference type. Then you actually need to pass the sys_id and display value. If you only pass one of them, an additional call will be made (= performance loss).
Kind regards,
Mark
---

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks Mark, I though I updated my client script with all 6 variables but looks like I forgot to save.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
are are you able to provide instruction on how to set this up. I'm still learning the inner workings of SN and scripting and don't know where exactly to place this.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
You can go to Script Includes and create commonUtils. Example
Go to Maintain Item and Open catalog item that you want to use this script on.
And create Catalog Client Script
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Mike,
I am using the same but what should be done if we are using the list collector as a variable and want to populate multiple users job title??
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Mike,
I tried your script. Department & Manager are showing sys_id where as they are reference field on my catalog item.
Also i tried to add
SI
var emailID = gr.email;
response.emailID = email;
CS
g_form.setValue('email', response.emailID);.
It's not working.
Instead it's showing a Javascript error.
Please suggest.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content