how to get full name for tree picker

Adil JEBLI
Mega Expert

Hi,

Im trying to get the full name when choosing several parent in a field the has tree_picker = true;

for example: The location field is configured as a tree by default so when you choose a a city for example you get just the name of the city but you have configured your field by (location.full_name) you get the city and its country.

do you have any idea how i can do that please.
thank you.

1 ACCEPTED SOLUTION

ghsrikanth
Tera Guru

Hi Adil,



I have implemented in my local system and everything is working fine.


Please find the details of the implementation -


The table definition as follows - Parent field should have an attribute tree_picker = true


Screen Shot 2016-03-14 at 11.27.01 PM.png



The Full Name column should be calculated and code should be like this -



Screen Shot 2016-03-14 at 11.27.29 PM.png



FYI, the code below -


(function() {


  var resultName = current.u_name;


  var parentId = current.u_parent;



  if (!gs.nil(parentId)) {


  var grParent = new GlideRecord('u_location_sri'); //write your table here


  grParent.addQuery('sys_id', parentId);


  grParent.query();


  if (grParent.next()) {


  resultName = grParent.u_full_name +"/"+current.u_name;


  }


  }


  return resultName;


})()



I have inserted few records to test the functionality and everything is working fine -



Screen Shot 2016-03-14 at 11.28.32 PM.png



I think your issue is resolve, hopefully



Mark if it is correct or helpful.



Tomorrow, I will try to give you the details of creating the table without column name starting with 'u_'


View solution in original post

21 REPLIES 21

ghsrikanth
Tera Guru

You can use the attribute - ref_ac_columns - listing the fields which should display in the reference picker -


Auto-Complete for Reference Fields - ServiceNow Wiki


Dictionary Attributes - ServiceNow Wiki


ref_ac_columnslist of field names separated by semi-colonsany reference field with an auto completer (see ref_auto_completer)Specifies the columns whose display values should appear in an auto completion list in addition to the name. See the cmdb_ci field ("Configuration Item") on the Incident form for a working example.

Mark if it is helpful or correct, feedback is apprciated


Thanks for the answer  



the solution you have suggested is not what i want, in your case there is an autocompleter and the field is not a tree picker, so it suggest just columns names in when you search.



what i want is to get the full name (parent1/parent2/parent3/son) when clicking the son in the tree.



for example: for the field location, we can choose the location as a tree:


Capture.PNG




if i click "401 Crestwood Blvd, Birmingham AL" i get this into the field:


aazdxa.PNG



but i can configure my form to get the full name of the location, i mean all parent of that location like this:


adada.PNG



in servicenow this option is available for the location field, the location field by default has tree picker as true in its attributes.


So the question is how i can do that for my own field , i want to add a field and configure its tree picker attribute as true, and get the full name



Thank you


ghsrikanth
Tera Guru

Thanks for explaining in detail, I think you have to follow an heirarchy in constructing the new table.


In the new table, there should be a parent field which refer to its own self, like in Location table -



In the new table, enter a top record, for example


- Americas,


- then North Americas (Americas will be parent for this record)


- then California (North Americs will be parent...) etc.



And when you refer this new table anywhere, please make tree_picker = true. I think this will list the new table's records in heirarchial way -



Hope this helps -



Screen Shot 2016-03-14 at 7.51.24 PM.png



There is parent field which is reference to location table itself.




Mark if it is helpful or correct, feedback is appreciated


Thank you Srikanth for your answer, but i think you still don't undetstand the question, i have already did the same schemat, i have a parent that
refer to same table, i made that in success.
try to configure the form layout and add the location and the location.full_name and you will understand my question.
after choosing you should have this result:
location: (what you choosed only) ex: new york
full name: (all parent) ex: Americas/USA/new york



thank you so much.