
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2017 10:11 AM
Hello community.
I have a client script for a service catalog item that works perfectly when accessed via the regular ServiceNow UI.
When the same service catalog item is accessed via the Service Portal, the script is not working. We have the UI type set to "both" (see screenshot of script).
Here's what our script does and what we'd like it to do when the service catalog item is accessed via the Service Portal:
After a user selects a person in the reference field #1 (variable we called "LaptopUser"), the associated manager for the user in field #1 is pulled into reference field #2 (variable called "LaptopUserManager").
As mentioend before the client script works great when accessing this service catalog item through the non-service portal UI.
Any help would be most appreciated. Thank you all for your time and help.
//Uses "LaptopUser" value to look up "Manager" value in the sys_user form, add value to "LaptopUserManager".
function onChange(control, oldValue, newValue, isLoading) {
var clearvalue = '';
var id = g_form.getValue('LaptopUser');
var user = new GlideRecord('sys_user');
user.addQuery('sys_id',id);
user.query();
if ( user.next() ) {
g_form.setValue('LaptopUserManager', user.manager);
}else{
g_form.setValue('LaptopUserManager', clearvalue); //If "LaptopUser" is null, sets "LaptopUserManager" to null value.
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2017 10:47 AM
Hello Antonio,
I have seen similar issues like that where clients scripts are working in regular view but not on portal. One common thing is portal expects some kind of call back function when you use either query or getreference.
Here is the script using getReference
function onChange(control, oldValue, newValue, isLoading) {
var clearvalue = '';
var user = g_form.getReference('LaptopUser', callback);}
function callback(user){
if(user){
g_form.setValue('LaptopUserManager', user.manager);
}}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2017 12:22 PM
Hi,
I found the solution.
Thank you so much for the help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2020 06:27 PM
Could you please tell me what is the solution for this?