My catalog Client Script is not working on the service portal inspite of setting the correct UI type. How can I solve this?

Aditya Sinha
Tera Contributor

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

1 ACCEPTED SOLUTION

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

}

.

 

Best Regards
Aman Kumar

View solution in original post

8 REPLIES 8

Aman Kumar S
Kilo Patron

Are you using getReference by any chance?

Also, can you share your code?

Best Regards
Aman Kumar

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);

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

}

.

 

Best Regards
Aman Kumar

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