how to show tree selection values with following criteria?

IVB2020
Kilo Contributor

Hi all,

Tree Structure:

Root =  Global

Node 0 = Country

Node 1 = Sites

Table is "Location"

Only values in Node 1 will be saved in "Location". Node 0 and Root will be used as a helper to automatically select values within its hierarchy. Selecting Root will automatically select ALL Node 0 and Node 1 values within its hierarchy. Selecting a Node 0 value will automatically select all Node 1 values within its hierarchy. De-selecting a Node 1 value de-selects its corresponding Node 0 and Root, if applicable. When reopening the Catalog Item, the tree selections will only show currently saved locations.

6 REPLIES 6

DrewW
Mega Sage
Mega Sage

So what exactly are you asking?  How to display this?  What to build to display this?  Something else?

If you are asking how do display it you are going to have to build a UI Macro for the platform interface and a widget for the Service Portal.  Then add a Macro var to your catalog item.

IVB2020
Kilo Contributor

My question was how to display this. And also is it possible to store these value in variable and next time when the same user opens the catalog item the variable has to show the previous value he has selected. Is it possible?

It is, like @David Arbour mentioned you can use tree_picker=true but thats going to require your data to be structured in a very specific way, meaning you have to have a single parent field that refers back to the same table if memory serves.  So if your data is not going to be in a table structured that way then you will have to build something custom.

The "Custom" (It was Macro in older versions) var type allows you set a UI Macro and a Widget to use.  UI Macro for the platform interface and Widget for the Service Portal interface.  It provides a place to store some text data.  So to store the selections you convert your data to a text format using JSON or other method and then store it using something like the below if its a SP Widget.

if(typeof $scope.page.g_form != "undefined"){
	$scope.page.field.value = JSON.stringify(dataToStore);
}

When the widget loads you can just check the above location to see if there is a value and if so use that to render the widget.

For the UI Macro I believe you can just use g_form.setValue to store the information but the load will need to be done in the Jelly.

 

So with all of that said if you can use the tree picker then do so and you will have one value stored in a reference field.

 

If you need to use user preferences but I do not think you do.
http://www.john-james-andersen.com/blog/service-now/servicenow-user-preferences-server-client-access.html

 

David Arbour
Tera Guru

To make a field display an hierarchical collection of records as a tree, simply add "tree_picker=true" as an attribute to the field referencing the Location table. The rest of this should be achievable by structuring your data properly in the Location table.