I’m creating a list of serial numbers with associated characteristics and displaying them in a Table widget. Once they are created, an operator has to manually enter data in to populate one of the fields called the ESN. I can’t figure out how to update a field in the table.
I have a linked variable, but updating that doesn’t update the array. If I could tell which index was selected, I could pop that out and pop it back in, but I can’t figure out how to tell which index of the array is selected
Hi @Gary, thanks for the question. Sorry to have to ask a basic question: can you really quickly confirm for me that the datasource for this table is an array of objects and not a Tulip table? It would look like the screenshot below.
The basic technique we’re using here is that we’re feeding a list of ESNs through the looping widget to count how many items there are in the list before we hit our selected ESN. That count is our index position.
Here’s the breakdown:
Make sure there’s a linked placeholder variable assigned for a selected row in your table.
use the MAPTEXTTOLIST() function to pull a list of ESNs from the object list
Run that array of ESNs through the looping widget to calculate the index position
(here’s the hacky part) Push a new object onto the end of the original object array
Swap the object at the end of the array with the object at the calculated index position, and then delete the obsolete object from the end of the array
Here’s the process:
1. Make sure your table has a linked variable for selected rows
What you’re doing here is incrementing a count every time a value IS NOT your desired ESN. When the looper encounters the correct ESN, it saves that value to another variable to prevent the list from incrementing through n.
Note that the final if/else condition is accounting for the scenario when your desired value is the first in the list.
5. Update the data by pushing the linked variable onto the end of the original object list, and then swapping that variable with the object at the desired index position. Delete the old record from the end of the object list
@Gary@John There is another way to accomplish this without looping.
You could do something like this (verified as working). Basically, just pull out the field that you want to use for search, provided they are all unique, and map it to another array. Then find your value in that array and get its index. Then save your changes back into the original array at the index.