Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Auto populate Location(location) Based on the Users selection.

Sitakanta Bej12
Tera Contributor

My Requirement is in service catalog request  we have two variables 
1) reee_joiner_name (Type=Reference. Reference table is "sys_user")
2)Location(Type=SingleLine Text)
When we select the reee_joiner_name , Location will be autopopulate based on the reee joiner name for user.

I have written the below Onchange catalog client script ::


var Rejoin = g_form.getReference('reee_joiner_name',callback);
   function callback(Rejoin){
       g_form.setValue('phone_number',Rejoin.mobile_phone);
       g_form.setValue('location',Rejoin.location);
   }

According to this code Phone number will displaying fine. But in the Location field(location) they displaying the sys_id of the location. But my requirement is displaying Location name.

Please help me Regarding this.

 

11 REPLIES 11

Yes, Chandra its good.

Hi @kommechandra,

 

If your onchange client scripts, then you will use newValue/ oldValue for selected variable or field.

 

      locationGA.addParam("sysparm_user_id", g_form.getValue('reee_joiner_name'));

 

If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers.
Thanks,
Sagar Pagar

The world works with ServiceNow

Hi @Sitakanta Bej12,

 

Have you solved this? Let me know if have any queries.


If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers.
Thanks,
Sagar Pagar

The world works with ServiceNow

Harish Bainsla
Kilo Patron
Kilo Patron

Try this

var Rejoin = g_form.getReference('reee_joiner_name', callback);

function callback(Rejoin) {
g_form.setValue('phone_number', Rejoin.mobile_phone);
g_form.setValue('location', Rejoin.location.getDisplayValue());
}

Hi Harish,

 

I have also tried nothing will be displaying when we using getDisplayValue(); their