The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Can I populate 'Location' Reference Field with Location 'Full Name' based on 'Space' Reference Field

WazzaJC
Tera Expert

Can I populate 'Location' Reference Field with Location 'Full Name' based on 'Space' Reference Field

 

Hi Team - I would really appreciate your help/guidance, on how I can achieve this.

 

I believe it would be an onChange Client script run on the Incident table.

 

On the 'Incident' Form, I have configured 3 custom fields: Building (u_building), Floor (u_floor) and Space (u_space).

 

These are all Reference fields, linked to the Location table (cmn_location).

Building populates just with Location type = Building values.

Floor populates just with Location type = Floor (based on Parent Building) values.

Space populates just with Location type = Space (based on Parent Building and Floor) values.

 

One looks up logically: Building > Floor > Space in my Incident form - once Building is chosen, Floor can be chosen, then the relevant Space can be chosen.

 

What I need to do is - I would like to auto-populate the 'Location' Reference field with the Location 'Full Name' based on the final 'Space' that is selected in the 'Space' Field (every space relates back to a parent Floor, which relates back to a parent Building) - hence has an associated Location 'Full Name' in the standard (cmn_location) table.

 

The Location 'Full Name' has the format: Building/Floor/Space, a system maintained field, as in the standard 'Location' (cmn_location) table.

 

How can I write the onChange Client Script, which upon change in the 'Space' (u_space) field, this will auto-populate the 'Location' (location) reference field, with the relevant Location 'Full Name', that is specifically associated with that 'Space' ? (Building > Floor > Space are all linked in Parent-Child relationship, as per standard Location table/tree functionality).

 

I have attached a screenshot to help as guidance as to the format of my 'Incident' Form.

 

Thanks ever so much for an help/guidance on this - much appreciated.

3 REPLIES 3

Saurav11
Kilo Patron
Kilo Patron

Yes you can do it using onchnage client script the structure will be as below:-

 

var gr = new GlideRecord('cmn_location');  
gr.addQuery('building', 'buildingincident'); 
gr.addQuery('floor', 'floorincident'); 
gr.addQuery('space', 'spaceincident'); 
gr.query(); 
if(gr.next()) { 
  g_form.setValue('location',gr.sys_id);
}

 

Now the value which will be displayed on the location able will the display value field  of the location table.

 

Please mark my answer as correct based on Impact.

Hi Saurav,

Thanks ver much - are you 100% sure about this solution/script?

It looks like it is trying to do something, but it is not working for me as expected.

Does your script exactly take into account the details I have mentioned in my note regards custom fields (u_building, u_floor, u_space) for example?

When I am trying your script, it is not bringing back the Location Full Name, that relates to the value in the 'Space' field.

Please advise if additional script adjustments are needed?

Many thanks.

Hello,

 

It depends on how you want to query it if you just want to query to based on space and if space is unique for all the records then you can try the below. please replace the fieldname accordingly in the script:-

 

var space=g_form.getValue('u_space');
var gr = new GlideRecord('cmn_location');  
gr.addQuery('u_space', space); 
gr.query(); 
if(gr.next()) { 
  g_form.setValue('location',gr.sys_id);
}

 

Please mark my answer as correct based on Impact.