Read a Dataset and print the data selected from the list

hola a todos quisiera me may help, quiero leer un dataset.

actual mente ya lo lee pero solo me imprime el dato del ROW que coloco en la linea de codigo y requiero que lea el dato sellecionado de la lista

por ejemplo si colo 0 me lee el numero 0 de mi lista aun quen tenga seleccionado otro al momento de imprimir

Type = system.tag.read (“Type_Stop”).Value.getValueAt (0, ‘Type’)

Hi Antonio,

In order to answer the question, you will need to specify how you are selecting the row that you want to read. For example, are you putting the dataset into a table component and you are selecting a row in the table? Or, are you having the user enter a number into a Numeric Entry Field and that number is the row that you want to read from the dataset?

There are many possible ways to “select” a row from the dataset. How are you doing that?

So google translate might be a little off...

Hello everyone, I would like to be able to help you, I want to read a dataset.

Currently it already reads it but it only prints the ROW data that I put in the line of code and I require that it read the data selected from the list

For example if I put 0 it reads the number 0 of my list even if I have another selected at the time of printing

I have a dropdown list and I have a label related whit this dropdown list

I need read the data select in this dropdown list

Are you using vision or perspective?

1 Like

NOTE: as @nminchin mentioned above… I assumed you are using perspective, so this code is written for that case.

Since you say that you already have the labels made for the dropdown, what you need to do is make sure that the value that is associated with each label is the row that you want to select for that label. Then you can access the value from the dropdown list and use it to read the row from the dataset like this:

row = self.getSibling('Dropdown').props.value
Type = system.tag.read ('Type_Stop').Value.getValueAt (row, 'Type')

This is assuming that you are running this code in a component event of a component that is a sibling of your dropdown. You could also run this could from the actionPerformed event of your dropdown component so that the data from the dataset would be read each time you change which dropdown option is selected. That code would look like this:

row = self.props.value
Type = system.tag.read ('Type_Stop').Value.getValueAt (row, 'Type')

retur the next error whit the first code

([default]Botones/Linea_Disco/Conteo Falla Disco/Falla Linea Disco, valueChanged) Error executing tag event script: Traceback (most recent call last): File “tagevent:valueChanged”, line 7, in valueChanged NameError: global name ‘self’ is not defined

@antonio.sanchez You are getting that error because you are running that script in a tag changed event script, which does not have access to the dropdown component that you are using the select the row.
What you can do is create a bidirectional binding on the dropdown’s value property to a new tag. Then in your tag valueChanged script you can read that new tag and use that value as the row.

OK, I’m going to create a event focus in my dropdown for write my label.

tag = system.tag.read(event.source.selectedValue)
system.tag.write("TAG_Type")

As it looks like you’re on v7.9, be sure to use a client tag. You don’t want multiple users writing to the same tag they are trying to use as a filter. :wink:

Just so we understand, you are using the dropdown to filter a dataset? So, for example, if the user selects ‘ABC’, you want all the rows with ‘ABC’?

1 Like

An illustration of my question.

basically I want to do

is that the user selects an option from the list and that clicking on the button saves the information of the data selected in the list

basically that would be

It's still very cryptic.. so would the process be:

  1. User selects an item from the dropdown component. For example the items are:
  • Pump 1
  • Pump 2
  • Pump 3
    User selects 'Pump 2'
  1. User presses a "save" button. What happens to 'Pump 2'? Where do you want to save this to? You say

Do you mean you want to add the item into the dropdown list again?
E.g. the dropdown item list would become:

  • Pump 1
  • Pump 2
  • Pump 3
  • Pump 2

Perhaps some context might be useful: what are you actually intending to use this for? What is the end goal of what you're trying to do? E.g. "I want the user to be able to select a pump from the list and then display its information on the screen"

Also,

You are getting this error because the code @lrose provided was for Perspective, and from what it sounds like and from your other posts with screenshots, you are using Vision, so this code won't work.

Hmmmm…now I’m providing code as another user? :man_shrugging:

Did I miss something? :joy:

Haha, my bad, I’m just used to seeing your replies with code in it. My brain switched off and went into autonomous mode I guess :smile: I meant to say @chandler.teigen

2 Likes

I have this Dropdown List

image

and in the property I have this list

I have a button (2-state toggle) in this button I have a tag whit a scrip for insert in a data base.

And I have a other tag where I want to send the data that the user selects from the list and thus be able to send it to the botton script and be able to save it in the database.

Okay, I’m starting to understand.

A few more questions. I am old, so be patient. :slight_smile:

  • What does the toggle button itself do? Does it just write a one or a three to the tag, or are there other things it does?
  • Does anything else write to this tag?
  • In the operation, does the user have to toggle the button, then toggle it again before another write to the database can happen? Or will you prefer to write to the database every time the button is pressed?
  • Are the dropdown and button in the same window? If yes, we should be able to put this script on the button action performed property (with some minor modification), and not have to use a tag as a ‘middleman’.

What does the toggle button itself do? Does it just write a one or a three to the tag, or are there other things it does? I require you to give me either the number of the selected line or the string of text of the line

Does anything else write to this tag?No

In the operation, does the user have to toggle the button, then toggle it again before another write to the database can happen? Yes

Or will you prefer to write to the database every time the button is pressed?No, because we keeps track of how long the button has been “ON”

Are the dropdown and button in the same window? Yes

I still have problems to be able to do what I want

now I mark that error:

File "event:mouseClicked", line 1, in

TypeError: read(): 1st arg can't be coerced to String

tag = system.tag.read(event.source.parent.getComponent('Dropdown_Tipo_Paro').data)
system.tag.write("Botones/Linea_Disco/Conteo Falla Disco/Tipo_Falla",tag.value)

The first parameter of the system.tag.read() function must be a string value which is the tag path of the tag you want to read.

You’re supplying an entire dataset, the function doesn’t know how to handle it.