# How to use custom method to get tag tree browser selected field value?

**URL:** <https://forum.inductiveautomation.com/t/how-to-use-custom-method-to-get-tag-tree-browser-selected-field-value/44479>\
**Category:** Ignition\
**Created:** [March 15, 2021, 4:50pm UTC](https://forum.inductiveautomation.com/t/how-to-use-custom-method-to-get-tag-tree-browser-selected-field-value/44479 "2021-03-15T16:50:00Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [March 15, 2021, 4:50pm UTC](https://forum.inductiveautomation.com/t/how-to-use-custom-method-to-get-tag-tree-browser-selected-field-value/44479/1 "2021-03-15T16:50:00Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/8/28848e873800aa490bd4dc9580261a6818fddcba.png) - script used in list component (custom method i have written this script)

In line 18 in my script i don’t know how to call tag tree browser selected tag path to the line

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/4/84ecf50f4995b758bfa296708668cd41b786a943.png) - getting this error

please help me out get solution

i tested by giving line 18 like this

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/f/bfb0e199b85be51d6cfc9e338c0e8e1e90020dbd.png)

my output is

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/7/6759bd92e426f60ea70d8398d7d7947ea66ff205.png) - getting output like this

i am trying to drag and drop tags from tag tree browser to list component

if any correction in my script please let me know

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [March 15, 2021, 5:02pm UTC](https://forum.inductiveautomation.com/t/how-to-use-custom-method-to-get-tag-tree-browser-selected-field-value/44479/2 "2021-03-15T17:02:57Z")

</div>

The selected paths should come over as part of the Transferable.

line 19 in your code is looking for the paths variable to be a list of lists.

In your test if you did:

```auto
paths = [['test']]

```

you would see the result you were expecting.

However, you should be able to get the paths from the Transferable that comes with the event object e

like this

```auto
paths = [[path] for path in e.getTransferable().getTransferData(ListOfQualifiedPath.FLAVOR)]

```

This list comprehension constructs a list of lists from the selected paths. It is functionally equivalent to the following:

```auto
newList = []
for path in e.getTransferable().getTransferData(ListOfQualifiedPath.FLAVOR):
    newList.append([path])

```

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [March 15, 2021, 5:22pm UTC](https://forum.inductiveautomation.com/t/how-to-use-custom-method-to-get-tag-tree-browser-selected-field-value/44479/3 "2021-03-15T17:22:45Z")

</div>

> [@lrose](#):
>
> newList = for path in e.getTransferable().getTransferData(ListOfQualifiedPath.FLAVOR): newList.append([path])

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/e/def7199eabde72143988b625f337eaa6faff11cb.png)

i am getting this error when i use this 3 lines this is the issue i am facing past one week . please give any alternative solution

my script

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/3/f3023ed5fa8d9e682dc8ef24a12507291d8cc856.png)

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [March 15, 2021, 5:28pm UTC](https://forum.inductiveautomation.com/t/how-to-use-custom-method-to-get-tag-tree-browser-selected-field-value/44479/4 "2021-03-15T17:28:17Z")

</div>

[test\_20210315225736.zip](https://forum.inductiveautomation.com/uploads/short-url/piv9gYz74G8RZBvTdMIN7BIHbsU.zip) (7.3 KB)

my project file can you check anything needs to be change?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [March 15, 2021, 6:20pm UTC](https://forum.inductiveautomation.com/t/how-to-use-custom-method-to-get-tag-tree-browser-selected-field-value/44479/5 "2021-03-15T18:20:26Z")

</div>

Okay, so I had some free time today, and this will be a nice to have for my application so I dug in a little bit more.

Turns out that if you have the Tag Browse Tree mode configured as a Readtime Tag Tree then you get a different Transferable type.

If your mode is set to ‘Realtime Tag Tree’ then the transferable that is used is a ListOfNodeBrowseInfo  
If your mode is set to ‘Historical Tag Tree’ the the transferable that is used is a ListOfQualifiedPath

I am sure there are reasons for that in the background.

That means your code needs to change slightly to use the correct Transferable Flavor

NOTE: If you have added the listener in the InternalFramActivated event you will need to close the window in the designer and re-open it once the change has been made.

```auto
from java.awt.dnd import DropTargetAdapter, DropTarget
from com.inductiveautomation.ignition.client.tags.dnd import ListOfNodeBrowseInfo
		
class customDragDropListener(DropTargetAdapter):
	_comp = None
	def __init__ (self,comp):
		DropTargetAdapter. __init__ (self)
		self._comp = comp
				
	def drop(self,e):
		e.acceptDrop(e.getDropAction())
		paths = [[node.getFullPath()] for node in e.getTransferable().getTransferData(ListOfNodeBrowseInfo.FLAVOR) if not node.hasChildren() and node.getObjectType().toString() != 'Provider']
		self._comp.data = system.dataset.addRows(self._comp.data,paths) if self._comp.data.columnCount > 0 else system.dataset.toDataSet(['Selected Tags'],paths)
				
ddl = customDragDropListener(self)
DropTarget(self,ddl)

```

Note that his will not accept a Folder or Provider, I didn’t take the time to handle that.

To properly handle these you will need to write a function which utilizes a recursive browse to gather the paths on a thread other than the GUI thread, should you want to handle a folder or provider in any way other than doing nothing. I have chosen to ‘ignore’ those items with this code.

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [March 15, 2021, 6:42pm UTC](https://forum.inductiveautomation.com/t/how-to-use-custom-method-to-get-tag-tree-browser-selected-field-value/44479/6 "2021-03-15T18:42:10Z")

</div>

> [@lrose](#):
>
> from java.awt.dnd import DropTargetAdapter, DropTarget from com.inductiveautomation.ignition.client.tags.dnd import ListOfNodeBrowseInfo class customDragDropListener(DropTargetAdapter): \_comp = None def **init** (self,comp): DropTargetAdapter. **init** (self) self.\_comp = comp def drop(self,e): e.acceptDrop(e.getDropAction()) paths = [[node.getFullPath()] for node in e.getTransferable().getTransferData(ListOfNodeBrowseInfo.FLAVOR) if not node.hasChildren() and node.getObjectType().toString() != 'Provider'] self.\_comp.data = system.dataset.addRows(self.\_comp.data,paths) if self.\_comp.data.columnCount \> 0 else system.dataset.toDataSet(['Selected Tags'],paths) ddl = customDragDropListener(self) DropTarget(self,ddl)

its working fine. thank you so much for your time. I have learned many things from you.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [March 15, 2021, 6:57pm UTC](https://forum.inductiveautomation.com/t/how-to-use-custom-method-to-get-tag-tree-browser-selected-field-value/44479/8 "2021-03-15T18:57:20Z")

</div>

I would not call it a small change.

You’ll need to implement a recursive browse.

To do it properly you will need to use

system.tag.browse  
system.util.invokeAsynchronous  
system.util.invokeLater

If you look through the forum there are several examples and posts detailing the proper use of those functions.

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [September 22, 2021, 6:17am UTC](https://forum.inductiveautomation.com/t/how-to-use-custom-method-to-get-tag-tree-browser-selected-field-value/44479/11 "2021-09-22T06:17:17Z")

</div>

@lrose

i just want to drga and drop only the tag path -"[MQTT Engine]Edge Nodes/Montreal/Energy/EPI/Total\_Consumption\_kWhTON"

**i dont want to drag and drop** **[MQTT Engine]Edge Nodes/Montreal/Energy/EPI/Total\_Consumption\_kWhTON.EngUnit"** not the path contains after the dot

is there any way to avoid and i need to show popup like if the drag and drop with .eng unit or some other thing

i want to indicate them please drag and drop the proper tag path

is there any way to add this feature in script?

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [September 22, 2021, 6:49am UTC](https://forum.inductiveautomation.com/t/how-to-use-custom-method-to-get-tag-tree-browser-selected-field-value/44479/12 "2021-09-22T06:49:54Z")

</div>

put `.split('.')[0]` after the string will split it up around the dots and take the first one if thats the one you want

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [September 22, 2021, 7:04am UTC](https://forum.inductiveautomation.com/t/how-to-use-custom-method-to-get-tag-tree-browser-selected-field-value/44479/13 "2021-09-22T07:04:48Z")

</div>

> [@victordcq](#):
>
> .split('.')[0]

thanks i will try to implement it according to my issue

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [September 22, 2021, 7:10am UTC](https://forum.inductiveautomation.com/t/how-to-use-custom-method-to-get-tag-tree-browser-selected-field-value/44479/14 "2021-09-22T07:10:10Z")

</div>

i am getting output like this

[[[MQTT Engine]Edge Nodes/Vidalengo/Energy/EPI/Total\_Consumption\_kWhTON.EngHigh]]

i want to use if condition it .dot is there in ouput i want to show popup  
other wise i want to pass

any idea for use if condition for my output?

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [September 22, 2021, 7:13am UTC](https://forum.inductiveautomation.com/t/how-to-use-custom-method-to-get-tag-tree-browser-selected-field-value/44479/15 "2021-09-22T07:13:01Z")

</div>

i dont fully understand the question…  
But i think this should do it  
`if '.' in string:`

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [September 22, 2021, 7:35am UTC](https://forum.inductiveautomation.com/t/how-to-use-custom-method-to-get-tag-tree-browser-selected-field-value/44479/16 "2021-09-22T07:35:01Z")

</div>

exactly this is what i want  
if ‘.’ in string:

simple when i drag and drop tag i dont want the string after the dot  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/b/8b859d564f3995cb416c3220ea65f5b0586c8821.png)  
i only want tag upto consumption\_KWTON… if any person try to drag and drop with engunit or some other think i want to show popup  
hope now you understood  
thanks

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [September 22, 2021, 11:29am UTC](https://forum.inductiveautomation.com/t/how-to-use-custom-method-to-get-tag-tree-browser-selected-field-value/44479/17 "2021-09-22T11:29:02Z")

</div>

You can handle this in a couple of different ways.

1. You can just split the path and ignore the property specification in the transferable.
2. You can break apart the comprehension and show a message box, or pop up if you prefer.

In the second case you will need to determine if that means not excepting the entire drop or not.

Case 1

```auto
	def drop(self,e):
		e.acceptDrop(e.getDropAction())
		paths = [[node.getFullPath().split('.')[0]] for node in e.getTransferable().getTransferData(ListOfNodeBrowseInfo.FLAVOR) if not node.hasChildren() and node.getObjectType().toString() != 'Provider']
		self._comp.data = system.dataset.addRows(self._comp.data,paths) if self._comp.data.columnCount > 0 else system.dataset.toDataSet(['Selected Tags'],paths)	

```

Case 2

```auto
	def drop(self,e):
		e.acceptDrop(e.getDropAction())
		paths = []
        addPaths = True
        for node in e.getTransferable(e.getTransferData(ListOfNodeBrowseInfo.FLAVOR):
            if not node.hasChildren() and node.getObjectType().toString() != 'Provider']:
                path = node.getFullPath().split('.')
                if len(path) == 1:
                    paths.append(path)
                else:
                    addPaths = False #set flag to not add paths
                    break #if were not accepting the drop, no reason to continue the loop
        if addPaths:
		    self._comp.data = system.dataset.addRows(self._comp.data,paths) if self._comp.data.columnCount > 0 else system.dataset.toDataSet(['Selected Tags'],paths)
        else:
            system.gui.messageBox('Your message here for invalid drops')

```

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [September 22, 2021, 11:41am UTC](https://forum.inductiveautomation.com/t/how-to-use-custom-method-to-get-tag-tree-browser-selected-field-value/44479/18 "2021-09-22T11:41:11Z")

</div>

thank you so much

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [September 22, 2021, 11:49am UTC](https://forum.inductiveautomation.com/t/how-to-use-custom-method-to-get-tag-tree-browser-selected-field-value/44479/19 "2021-09-22T11:49:57Z")

</div>

getting error for case 2 script

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/8/280cee12de2c073806f3eadaa7e03db84a9ca462.png)

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [September 22, 2021, 11:54am UTC](https://forum.inductiveautomation.com/t/how-to-use-custom-method-to-get-tag-tree-browser-selected-field-value/44479/20 "2021-09-22T11:54:05Z")

</div>

Not sure how the 0 got in there, but it should be an e

```auto
for node in e.getTransferable(e.getTransferData(ListOfNodeBrowseInfo.FLAVOR):

```

I’ve edited the code to correct the bug.

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [September 22, 2022, 9:27am UTC](https://forum.inductiveautomation.com/t/how-to-use-custom-method-to-get-tag-tree-browser-selected-field-value/44479/21 "2022-09-22T09:27:08Z")

</div>

@lrose

Hi ,  
I have tired same script in power table dragging and drop tags from tag tree browser to power table

its not working

any change we need to implement this feature in power table?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [September 22, 2022, 2:51pm UTC](https://forum.inductiveautomation.com/t/how-to-use-custom-method-to-get-tag-tree-browser-selected-field-value/44479/22 "2022-09-22T14:51:59Z")

</div>

This code works just fine for me when the drop target is a power table. What doesn’t work? What error are you seeing?

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [September 22, 2022, 3:24pm UTC](https://forum.inductiveautomation.com/t/how-to-use-custom-method-to-get-tag-tree-browser-selected-field-value/44479/23 "2022-09-22T15:24:21Z")

</div>

may be again i will check and let you know

[Next page](https://forum.inductiveautomation.com/t/how-to-use-custom-method-to-get-tag-tree-browser-selected-field-value/44479.md?page=2)
