Populating drop down list(dataset)


I would like to create drop down list, that will have 25 labels. Each label corresponds to group of six tags. I would then link the labels to the simple chart.
I can enter the 25 labels manually.
However, I would like to know if it is possible to write some script to populate the drop down menu.
I tried populating it by using the event handler, mouse click, but that doesn’t work if I click the drop down symbol.It only work when i click the text area adjacent to the drop down symbol.

The easiest way to populate a dropdown list from scripting would be to use a combination of a runScript expression function and your own custom script module. Follow these steps:

  1. In the designer let’s first make a script module function. From the menu select Project > Script Modules.

  2. Click on app. At the bottom click on the “Add a new module” icon (looks like a scroll with a plus icon).

  3. Name your module whatever you want like “dropdown.”

  4. Click on the new module and add a script function on the right under “Module Definition” like this:[code]def fillDropdown():
    import system
    header = [“value”, “display”]
    data = []

    data.append([1, “First Set of Tags”])

    return system.dataset.toDataSet(header, data)[/code]5) Press OK to save. We can now use that function in binding on the dropdown list.

  5. Bind the data property of the dropdown list to the following expression:runScript("app.dropdown.fillDropdown()", 0)The second argument is for polling. If you set it to 0 it only does it once when the window opens. If you set it to 1000 it will run the expression every second.

That is it. You will see the data fill in from your custom script. There are other ways to fill in the dataset but I prefer this method.

Thanks! :slight_smile: I could populate the drop down list with the code you gave.
But, After populating the Drop down list, I wanted to make a selection from the drop down list to select one of the groups. Based on my selection I would like to display the trend of 6 tags withing that group. If I change the group, the list of tags also change.
I tried to do this using the following script. the script in the script module ‘Chart’ is:

def fillchart(): import system data = [] header = ["values","path"] GroupNo = event.source.parent.getComponent('Dropdown').selectedValue temp = [1,2,3,4,5,6] if GroupNo = 1: tag = temp else for i in range(6): tag[i] = temp[i] + (GroupNo-1) * 6 for j in range(6): data.append(["Tag %i"%(tag[j]), "Path/Tag%i"%(tag[j])]) return system.dataset.toDataSet(header,data)

I linked the chart pen tag dataset binding property to the following expression

runScript("app.chart.fillchart()", 0)


The chart screen is red and when I click on the label of the drop down nothing happens.
Looking forward to a solution

You will get an error because you don’t have the event object in the app script module. You have to pass in the dropdown’s selected value in the expression. The script function will look like this:def fillchart(GroupNo): import system data = [] header = ["values","path"] temp = [1,2,3,4,5,6] if GroupNo = 1: tag = temp else for i in range(6): tag[i] = temp[i] + (GroupNo-1) * 6 for j in range(6): data.append(["Tag %i"%(tag[j]), "Path/Tag%i"%(tag[j])]) return system.dataset.toDataSet(header,data)The expression will look like this:runScript("app.chart.fillChart(" + {Root Container.Dropdown.selectedValue} + ")", 0)

Problem solved! Thank you! :slight_smile: :slight_smile:

Can you Show the script which you have written in your script module.
Where do i put the run script i.e “runScript(“app.chart.fillChart(” + {Root Container.Dropdown.selectedValue} + “)”, 0)” either in dropdown button or in tag dataset binding.