# Using the Collapsible Tree Template on Device Tags

**URL:** <https://forums.losant.com/t/using-the-collapsible-tree-template-on-device-tags/3521>\
**Category:** Help\
**Tags:** experience\
**Created:** [January 11, 2021, 8:54pm UTC](https://forums.losant.com/t/using-the-collapsible-tree-template-on-device-tags/3521 "2021-01-11T20:54:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Murdy](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@Michael\_Murdy](https://forums.losant.com/u/Michael_Murdy)\
**Post date:** [January 11, 2021, 8:54pm UTC](https://forums.losant.com/t/using-the-collapsible-tree-template-on-device-tags/3521/1 "2021-01-11T20:54:20Z")

</div>

Hello Losant support:

I am attempting to include the [Collapsible Tree Component Template](https://github.com/Losant/losant-templates/tree/master/library-templates/experiences/components/collapsible-tree) in my experience pages to allow for device breakdown based on the device tags. I have decided to attempt this approach vs utilizing experience groups due to the amount of permutations required for our device network. The desired menu would look something like this:

-\> myParentDeviceTag1  
–\>my1stChildDeviceTag1  
—\>my2ndChildDeviceTag1  
----\>device.name.[0]  
----\>device.name.[1]  
–\>my1stChildDeviceTag2  
—\>my2ndChildDeviceTag2  
----\>device.name.[3]  
—\>my2ndChildDeviceTag3  
----\>device.name.[4]  
-\> myParentDeviceTag2  
and so on…

I believe the [Collapsible Tree Component Template](https://github.com/Losant/losant-templates/tree/master/library-templates/experiences/components/collapsible-tree) can do this, but I am struggling to get the device tags organized into a parent / child list (similar to the output of the [Group: Summary Node](https://docs.losant.com/workflows/experience/summary-group/)). Can you provide some guidance on how I may achieve a parent/child list based on the desired device tags?

---

<div class="post-metadata">

**Author:** ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)\
**Post date:** [January 11, 2021, 9:56pm UTC](https://forums.losant.com/t/using-the-collapsible-tree-template-on-device-tags/3521/4 "2021-01-11T21:56:03Z")

</div>

Hey Mike,

This is possible but is a little more advanced. You would have to use the Function Node to build up the data structure of your list of devices to look like this:

```auto
"groupTreeResult": {
      "name": "(root)",
      "id": "(root)",
      "children": [
        {
          "name": "Top Parent",
          "id": "58dc4ec29e8df60001fbea01",
          "children": [...]
        },
        {
          "name": "Top Parent 2",
          "id": "58dc4ec29e8df60001fbea02"
        }
    ]
}

```

Or, you can customize the properties the template is looking for using [Arguments](https://github.com/Losant/losant-templates/tree/master/library-templates/experiences/components/collapsible-tree#arguments).

Since Losant doesn’t have a built-in way to relate parent and child tags, would you be able to tell me more about how you are defining that?

Thank you,  
Heath

---

<div class="post-metadata">

**Author:** ![Michael\_Murdy](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@Michael\_Murdy](https://forums.losant.com/u/Michael_Murdy)\
**Post date:** [January 12, 2021, 1:07am UTC](https://forums.losant.com/t/using-the-collapsible-tree-template-on-device-tags/3521/7 "2021-01-12T01:07:08Z")

</div>

Thanks for the response Heath!

I think I can work with the function node on this. If I am understanding right, it sounds like I should loop through all devices and then reference the appropriate tags as I write the intended output in the parent child relationship. As far as how we are defining that, I’ll attempt an abstract explanation here.

We have added a data table that outputs from our ERP system and defines both user tags and device tags. I’ve decided to limit the amount of experience groups as the permutations would become numerous. As a device is provisioned, it is assigned an identifier that matches that from our ERP system. We have a workflow that runs on a scheduled and as-needed basis to assign the appropriate tags from our ERP system onto the device (and user - separately).

The desired user experience here is one where the user can define how to best organize their device suite. For example, a sales user could organize by:

-\> Territory  
–\>Sales Representative  
—\> Account  
----\> Device type  
-----\> Device

Or, likewise, a corporate user could decide to organize by:

-\> Market Segment  
 → Brand Category  
—\> Parent Account Group  
----\> Location  
-----\> Device Type  
-------\> Device

From here, I believe I can return a single deviceId or array of deviceIds to apply to a context variable for the resulting dashboards.

If I can write the parent child relationship on the fly, this should be possible. Do you think this approach will work?

If so, do you think that the loop is the best method to incorporate with the function? And, if the loop is appropriate, I may need some guidance on how to find whether the parent value has been written and then add the appropriate children to that parent.

---

<div class="post-metadata">

**Author:** ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)\
**Post date:** [January 13, 2021, 6:43pm UTC](https://forums.losant.com/t/using-the-collapsible-tree-template-on-device-tags/3521/9 "2021-01-13T18:43:16Z")

</div>

Hey Mike,

I’m going to take this off the forums, as I have some questions that are pertinent to your application.

Look for an email from me shortly!

Thank you,  
Heath
