- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2022 08:44 AM
Hi all.
My OnLoad catalog client script written for a catalog item is not functioning when the catalog item is opened via the service portal (Note - It is functioning fine when I am using the "try it" button on the catalog item). I have set the UI type of the script to All. How can I solve this?
The script populates a few fields on the basis of a 'requester for' field
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2022 04:52 AM
You don't want to use gliderecord in a client script.
What you need is a onchange catalog client script:
Note: Make sure field names are correct
function onChange(control, oldValue, newValue, isLoading) {
if(isLoading){
return;
}
if(newValue == ''){
g_form.setValue('EmailId', ''); // check your field name here
g_form.setValue('LocationOfUser', ''); // check your field name here
g_form.setValue('PhoneNumber', '');
}
var requester = g_form.getReference('requestedFor', getUserDetails);// check your
field name for requested for
}
function getUserDetails(requester){
g_form.setValue('EmailId', requester.email); // check your field name here
g_form.setValue('LocationOfUser', requester.location); // check your field name here
g_form.setValue('PhoneNumber', requester.mobile_phone); // check your field name here
}
.
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2022 08:49 AM
Are you using getReference by any chance?
Also, can you share your code?
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2022 04:00 AM
I have created a custom form with Name, Location,EmailId and phone number as fields.
Name field has to be a RquesterFor field and as the name filed gets populated the other 3 fields get populated as well.
Emaild is an email field, Mobile Number is a single line text field and location is a reference field with reference cmn_location table
var gr=new GlideRecord('sys_user');
gr.addQuery('sys_id',gg);
gr.query();
gr.next();
g_form.setValue('EmailId',gr.email);
g_form.setValue('LocationOfUser',gr.location);
g_form.setValue('PhoneNumber',gr.mobile_phone);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2022 04:52 AM
You don't want to use gliderecord in a client script.
What you need is a onchange catalog client script:
Note: Make sure field names are correct
function onChange(control, oldValue, newValue, isLoading) {
if(isLoading){
return;
}
if(newValue == ''){
g_form.setValue('EmailId', ''); // check your field name here
g_form.setValue('LocationOfUser', ''); // check your field name here
g_form.setValue('PhoneNumber', '');
}
var requester = g_form.getReference('requestedFor', getUserDetails);// check your
field name for requested for
}
function getUserDetails(requester){
g_form.setValue('EmailId', requester.email); // check your field name here
g_form.setValue('LocationOfUser', requester.location); // check your field name here
g_form.setValue('PhoneNumber', requester.mobile_phone); // check your field name here
}
.
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2022 05:15 AM
Hi Aman. I made necessary changes to the code using getReference() like you've written .However the issue still persists .It is not working on the service portal but working on the "try it" button on the catalog item