- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2019 08:32 AM
I could use some help with an onChange client script for a catalog item on the service portal.
A variable called updateEmployeeProfile references the sys_user table. When the field is selected, I would like to update form variables like updateEmployeeFirstName and updateEmployeeLastName from the sys_user table first_name and last_name.
The variables do not update when updateEmployeeProfile variable is changed both on service portal and IT side.Thank you in advance!
---
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var user = new GlideRecord("sys_user");
user.addQuery("user_name", g_form.getValue('updateEmployeeProfile'));
user.query();
if(user.next())
{
var userid = user.sys_id;
g_form.setValue('updateEmployeeFirstName', userid.first_name);
g_form.setValue('updateEmployeeLastName', userid.last_name);
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2019 08:36 AM
You cannot use GlideRecord in the Service Portal. Change you script to something like below. You will just need to substitute your variables names and add code for things like first name last name. My script below is just pulling phone number and email.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
g_form.getReference('primary_developer_name', function(ref){
g_form.setValue('primary_developer_phone', ref.phone);
g_form.setValue('primary_developer_email', ref.email);
});
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2019 08:36 AM
You cannot use GlideRecord in the Service Portal. Change you script to something like below. You will just need to substitute your variables names and add code for things like first name last name. My script below is just pulling phone number and email.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
g_form.getReference('primary_developer_name', function(ref){
g_form.setValue('primary_developer_phone', ref.phone);
g_form.setValue('primary_developer_email', ref.email);
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2019 12:26 PM
You rock! Thank's for the quick response. This solved my issue.