# How to write tag with condition

**URL:** <https://forum.inductiveautomation.com/t/how-to-write-tag-with-condition/14137>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [April 25, 2017, 2:50pm UTC](https://forum.inductiveautomation.com/t/how-to-write-tag-with-condition/14137 "2017-04-25T14:50:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Slurpee](https://avatars.discourse-cdn.com/v4/letter/s/4da419/32.png) [@Slurpee](https://forum.inductiveautomation.com/u/Slurpee)\
**Post date:** [April 25, 2017, 2:50pm UTC](https://forum.inductiveautomation.com/t/how-to-write-tag-with-condition/14137/1 "2017-04-25T14:50:58Z")

</div>

I want to write the value of a numeric label to a tag.

I usually use this script in the property change to write into a tag.

if event.propertyName == “intValue”:  
value = event.source.intValue  
system.tag.write(“Output1”, value)

Now I want to add a condition to write in a particular tag based on a selection like a dropdown list  
as the value of the numeric label has a reference from the dropdown list.

Like if 1 is selected it will be for Output1  
2 will be for Output2 …

Can anyone help me on my script…

Thanks in advance…

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [April 25, 2017, 3:13pm UTC](https://forum.inductiveautomation.com/t/how-to-write-tag-with-condition/14137/2 "2017-04-25T15:13:37Z")

</div>

Yes, sure. Here is an example:

```auto
if event.propertyName == "intValue":
	selectedValue = event.source.parent.getComponent('Dropdown').selectedValue	
	if selectedValue == 1:
		tag = "Output1"
	elif selectedValue == 2:
		tag = "Output2"
	value = event.source.intValue
	system.tag.write(tag, value)

```

Or more elegantly it could be done like this:

```auto
if event.propertyName == "intValue":
	selectedValue = event.source.parent.getComponent('Dropdown').selectedValue
	system.tag.write("Output%s"%selectedValue, event.source.intValue)

```

---

<div class="post-metadata">

**Author:** ![Slurpee](https://avatars.discourse-cdn.com/v4/letter/s/4da419/32.png) [@Slurpee](https://forum.inductiveautomation.com/u/Slurpee)\
**Post date:** [April 25, 2017, 3:23pm UTC](https://forum.inductiveautomation.com/t/how-to-write-tag-with-condition/14137/3 "2017-04-25T15:23:35Z")

</div>

Thanks Nick @nmudge it is a big help for me as a newbie here… I truly appreciate it…😉

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [April 26, 2017, 12:58pm UTC](https://forum.inductiveautomation.com/t/how-to-write-tag-with-condition/14137/4 "2017-04-26T12:58:46Z")

</div>

While probably not what you need, this may be one to keep in mind for the future.  
You can use the dropdown menu’s dataset to define the tagpath and tag value to write for each item in the drop down menu. For this to work, you would need to add another column/field to the drop down menu’s data property called “TagPath” and “Value”.

```auto
ddm = event.source.parent.getComponent('Dropdown')
ds = system.dataset.toPyDataSet(ddm.data)
selectedValue = ddm.selectedValue

tagPath = ds[selectedValue]["TagPath"]
tagValue = ds[selectedValue]["Value"]
system.tag.write(tagPath, tagValue)

```

This will write the value in the Value field to the Tag defined by the TagPath in the dataset, for the selected index of the drop down menu.
