# Indirect tag binding in component script

**URL:** <https://forum.inductiveautomation.com/t/indirect-tag-binding-in-component-script/12352>\
**Category:** Ignition\
**Created:** [November 14, 2016, 5:40am UTC](https://forum.inductiveautomation.com/t/indirect-tag-binding-in-component-script/12352 "2016-11-14T05:40:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![roshanbhosale](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/roshanbhosale/32/4899_2.png) [@roshanbhosale](https://forum.inductiveautomation.com/u/roshanbhosale)\
**Post date:** [November 14, 2016, 5:40am UTC](https://forum.inductiveautomation.com/t/indirect-tag-binding-in-component-script/12352/1 "2016-11-14T05:40:17Z")

</div>

in my project there is an event where user has to enter a value into the text field and that value will be used as index for referencing the tag for e.g. suppose user enters 1 than the indirect tag “Tank{index}/product\_level” will be referenced accordingly with specified index number 1. is there a way to use indirect tag binding in component scripts?

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [November 14, 2016, 7:29pm UTC](https://forum.inductiveautomation.com/t/indirect-tag-binding-in-component-script/12352/2 "2016-11-14T19:29:36Z")

</div>

It depends on how you will be using it but you can build the string and use that.

```auto
tankNum = system.gui.inputBox("Enter tank Number",1)
if tankNum != None:
     tagRef="Tank"+tankNum+"/product_level"
     server = "Ignition OPC-UA Server"
     path = tagRef
     qualifiedValue = system.opc.readValue(server, path)
     print "Value: " + str(qualifiedValue.getValue())
     print "Quality: " + qualifiedValue.getQuality().toString()
     print "Timestamp: " + qualifiedValue.getTimestamp().toString()
else:
     system.gui.errorBox("You must enter a valid tank number!","Error!")
```

---

<div class="post-metadata">

**Author:** ![roshanbhosale](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/roshanbhosale/32/4899_2.png) [@roshanbhosale](https://forum.inductiveautomation.com/u/roshanbhosale)\
**Post date:** [November 15, 2016, 7:39am UTC](https://forum.inductiveautomation.com/t/indirect-tag-binding-in-component-script/12352/3 "2016-11-15T07:39:40Z")

</div>

hi,  
i have created 100 tags of same type but different index number. now, i have provided user a drop down list (whose data property is binded with the MySQL table) from which he can select the desired entity. in my case, from drop down list user can select one of the available truck number in the database. if that truck is in under process in plant than its status is available in one of the 100 tags i have created. each time user select the truck from drop down list than, i have to cross verify it against tags. if it is present in the tag than the message will popup as “you can not add this truck as it is already under process”  
now the problem is , i am using for loop for cross verifying this:  
truckNo = event.source.parent.getComponent(‘TruckNO’).selectedStringValue  
for x in range(1,101):  
#y = toString(x) #tried to use this but gets an error as “toString is not defined”, if i dont use it i get an error as"cannot concatenate ‘str’ and ‘int’ objects"  
path = “TT/TT”+x+"/szTruckNo" #this tas is created as string  
value = system.tag.read(path)  
if value == truckNo:  
system.gui.messageBox(“already FAN pending for the truck!”,“Warning”)

---

<div class="post-metadata">

**Author:** ![roshanbhosale](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/roshanbhosale/32/4899_2.png) [@roshanbhosale](https://forum.inductiveautomation.com/u/roshanbhosale)\
**Post date:** [November 15, 2016, 7:41am UTC](https://forum.inductiveautomation.com/t/indirect-tag-binding-in-component-script/12352/4 "2016-11-15T07:41:47Z")

</div>

see next message for the code i am using …sorry for indentation can not be seen for “for” and “if”

---

<div class="post-metadata">

**Author:** ![roshanbhosale](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/roshanbhosale/32/4899_2.png) [@roshanbhosale](https://forum.inductiveautomation.com/u/roshanbhosale)\
**Post date:** [November 15, 2016, 8:48am UTC](https://forum.inductiveautomation.com/t/indirect-tag-binding-in-component-script/12352/5 "2016-11-15T08:48:50Z")

</div>

[quote=“roshanbhosale”]  
truckNo = event.source.parent.getComponent(‘TruckNO’).selectedStringValue  
for x in range(1,101): "  
path = “TT/TT”+x+"/szTruckNo" #this tas is created as string  
value = system.tag.read(path)  
if value == truckNo:  
system.gui.messageBox(“already FAN pending for the truck!”,“Warning”)[/quote]

---

<div class="post-metadata">

**Author:** ![accyroy](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/accyroy/32/3386_2.png) [@accyroy](https://forum.inductiveautomation.com/u/accyroy)\
**Post date:** [November 15, 2016, 10:13am UTC](https://forum.inductiveautomation.com/t/indirect-tag-binding-in-component-script/12352/6 "2016-11-15T10:13:09Z")

</div>

You need to build the string using placeholders. %d is replaced with the value of x.

```auto
path = "TT/TT%d/szTruckNo" % (x) 
```
