Populate User Mobile number and location OnChange and Onload on catalog Item

SNOW46
Tera Contributor

Hi Everyone,

I have configured one Catalog Item in which I have added some varaibles as below.

1.Mandatory - preloaded with saved dataRequestor - Reference field to User table and I have added the default value as javascript:gs.getUserName() and it is populating onload of the form

2.Phone Number - Single Line Text field and given the default value as javascript:gs.getUser().getRecord().getValue('mobile_phone'). 

3.Site Location - Location field reference to Location Table. Default value is javascript:gs.getUser().getRecord().getValue('location').

4.Requester on Behalf of - Reference field to User table if user wants to request on behalf of any other user.

 

But I have some doubts when the form loads, the Location as well as SIte Location is not populating based on the logged in user.

And when I change the Requester name as well as Request on behalf of name and put some other user's name then the phone number field is not getting clear.

Can anyone suggest me on the same how to achieve this requirement. Is there anything do I need to configure any Catalog Client Scripts to perform the task.

 

Thanks,

SNOW@Das

13 REPLIES 13

Shambhu5
Kilo Guru

Hi Snow@Das,

For this you will have to write a Script Include and call that in Catalog Client Script using Ajax. This way you will achieve your goal.

Thanks

Please take a reference from below script:

Auto populate user information on Load 

Same Script include can be used for onChange catalog client script.

Please mark my answer as Correct/Helpful in case that helps.

Thanks

SNOW46
Tera Contributor

Hi Vishrut,

I went through the script. But I have some doubts like do I need copy and paste the variable name anywhere in Script Include Script. 

 

Script Include:

var requestor_details = Class.create();

 

requestor_details.prototype = Object.extendsObject(AbstractAjaxProcessor, {

  requestor_info: function() {

 

  var result = this.newItem("result");

 

  var logged_user = gs.getUserID();

 

  var user_detail = new GlideRecord('sys_user');

 

  user_detail.addQuery('sys_id',logged_user);

 

  user_detail.query();

 

  while(user_detail.next())

 

  {

 

  result.setAttribute("user",user_detail.sys_id);

 

  result.setAttribute("phone", user_detail.phone);

 

  result.setAttribute("email",user_detail.email);

 

  result.setAttribute("location",user_detail.location);

 

 

 

  }

 

  },

 

 

 

  type: 'requestor_details'

 

});

Please kindly let me know?

SNOW46
Tera Contributor

Hi Vishrut,

Can you please post your comments on my queries?

I am still awaiting for your response.