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

Prince Arora
Tera Sage

@Sitakanta Bej12 

 

First Approach:

You can only dot walk once in the getReference function

In order to get the display value or more dot walking you should use onChange client script with GlideAjax approach

 

For more info check this link 

 

Second Approach:

Make the location field data type as Reference to locations(cmn_location) table instead of single line text, it will work for you.

 

 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Sitakanta Bej12 

Why not use Utah feature of Auto-populate?

It will auto-populate the variable with the field you want from reference field.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader