I am a complete newbie at scripting so please be gentle.

I am attempting to take the combination of two dropdown boxes, determine the selected combination and then set an SQL tag based upon this combination. What I have done so far is create the dropdowns and setup the data tables associated with each. When the selections are made, the operator will push a pushbutton and the appropriate tag will be set. The first dropdown returns a value of 0, 10, 20, 30, etc… The second dropdown returns a value of 0 through 6 only. I created a Dynamic Property of the pushbutton that is bound to an expression that adds the returned values of the dropdowns. So I am able to generate a unique number for all dropdown combinations. Now the part where I have no idea what to do. How do I take this unique number, associate it with an SQL tag and then update the tag when the button is pushed? For clarity, the result of the two dropdowns say, 23 will always associate to tag x and only tag x, if the result were 11, it would always associate to tag y and only tag y. I will have 42 unique combinations of the dropdowns and have 42 tags that this will manipulate so a brute force method is acceptable to me. (I’m good at copy and paste :laughing: )


So, you just want to write a 1 to whichever tag is selected?

Let’s say you have two drop downs and a button all in the same container. “Dropdown1” has your “10s”, and “Dropdown2” has your “1s”. Lets pretend all of your SQLTags are called “TagX” in the root of the provider (that is, not under a folder). You could do the following on the button’s “actionPerformed” event:

tens = event.source.parent.getComponent("Dropdown1").selectedValue
ones =  event.source.parent.getComponent("Dropdown2").selectedValue
system.tag.writeToTag('Tag'+str(tens+ones), 1)

Now, I suppose you want your SQLTags to be bound to items in a device, so those would just be OPC Items that you brought in and renamed. The key takeaway here is that your can use the “writeToTag” function to address any tag path you want.

Hope this helps,

Looking at how you did that, I wish all of my tags were named like that and arranged differently than I currently have them.

I have seven PLCs (my 10’s in the first dropdown) and they are all the same. Their tags are all the same, just located under different folders in the Tags list.

The six selectable functions that I want to accomplish on each PLC (the 1’s) are also all the same and all have the same tag name (they’re just in different folders.)

So if my dropdown combination returns a 1, 11, 21, 31, 41, 51 or 61, it will always be the same tag name but located under a different tag folder.

I have been looking for a way to make a table (that the user would not see) that would associate the 42 possible returned values with the 42 tag names (brute force method.) This is no problem but how to compare what I get from the dropdowns to the table and update the tag is my problem.


You could just make a list (or lists) to contain all these tag names. Something like:tens = event.source.parent.getComponent("Dropdown1").selectedValue ones = event.source.parent.getComponent("Dropdown2").selectedValue folders = ["", "folder1", "folder2", "folder3", ...] fields = ["", "field1", "field2", "field3", ...] tagpath = "%s/%s" %(folders[tens], fields[ones]) system.tag.writeToTag(tagpath, 1)The only caveat is that the lists are zero based so you either have to include an empty string in the zero position or subtract one from the tens/ones values to get the numbers to match up right.

I see Robert just replied, but I’m going to post anyway, since I spent so long to write this up and it shows a basically-equivalent-but-slightly-different way of doing it.

How are the folders and tags named? If the folders are named like “PLC10, PLC20”, that’s easy enough. To map the tag name to the number, you could just hard code a “map” in python (a list would work, but we’ll use a map to make it clearer). So, modifying the previous example…

tagName = {1:'TagA',2:'TagB',3:'TagC'}
tens = event.source.parent.getComponent("Dropdown1").selectedValue
ones =  event.source.parent.getComponent("Dropdown2").selectedValue
system.tag.writeToTag('TopFolder/Device%s/%s' % (tens, tagName[ones]), 1)

So, there are two changes: the tag name is looked up in the map based on the value selected in ‘ones’, and I switched from “String concatenation” to “string formating” so I could replace two parameters in the template. If your not familiar at all with maps, string manipulation, etc (ie, you’ve never used python before), you might find it useful to go run through a quick overview somewhere. The basics of python are very easy to learn and will help a lot.

Anyhow, hope this gets you a bit further along. Basically, one way or another it should be relatively easy to map the input from the two drop downs to the actual tag, without resorting to a full out lookup table.


Colby and Robert, thank you for your help, I got it to work.

What I did was a modification to Colby’s original post. I dumped the whole tens and ones concept. Since all of my tags are the same for each PLC, the first dropdown now provides me with the folder name (PLC) that I want and the second dropdown provides me the tag name.

bldg = event.source.parent.getComponent("Dropdown1").selectedLabel
sequence = event.source.parent.getComponent("Dropdown2").selectedLabel

So no lookup table. :thumb_left: My dropdowns have tables of 7R x 2C and 6R x 2C. Nice and simple.