Issues with setting an Integer to an Index in an Instance

I have an application that is talking back and forth with a SQL database for Inventory.

I created the cards for mobile application, and found that I need to apply an index to the instances because the Cards do not have a highlight feature like the table does.

I have looked around on the forums and I have found some code that was suggest, but it seems I am still missing something as it gives me an error.

I want to be able to select a card and have it “move” data into a TabContainer that will allow an operator to checkout/edit inventory.

You might want to tell us what the error is, because nothing is apparent from the screenshot, supposing that is the code you’re talking about.

Concerning the code, I’m not sure what the query should be returning, but I doubt the script transform is using it properly: It expects value to be an integer, which is probably not the case since you’re using select *.

By the way, the whole script transform can be written like this:

def transform(self, value, quality, timestamp):
    return [{'index': i} for i in xrange(value)]

In short: Show us what you’re actually doing (query, code, bindings…), and the relevant results (the error in this case)

2 Likes

I have attached screen shots of the Query, what it is returning and the property I am binding that information to.

Since the Flex Repeater does not have a highlight, I have to assign an index to each of the instance that is returned. There could be 1 instance or 100.

image


image
Error Code

As expected, you’re passing the full result of the query (an array) to range, which expects an integer.

Here’s the transform you’re looking for:

return [dict(row, index=i) for i, row in enumerate(value)]

edit: Do what @lrose said, add the index in your query.

I would be tempted to do something like:

SELECT row_number() as Index,PartNumber,ItemCode,Description,Quantity,ProductPrice
FROM Inventory
WHERE
    PartNumber LIKE :PartNumberString OR
    ItemCode LIKE :PartNumberString OR
    Description LIKE :PartNumberString
ORDER BY
    PartNumber ASC

If you care about the index of the row number then you can add the OVER() function in as well.

SELECT row_number() over(ORDER BY PartNumber ASC) as Index, PartNumber,ItemCode,Description,Quantity,ProductPrice
FROM Inventory
WHERE
    PartNumber LIKE :PartNumberString OR
    ItemCode LIKE :PartNumberString OR
    Description LIKE :PartNumberString
ORDER BY
    PartNumber ASC

As for why your code is erroring, as @pascal.fragnoud stated, the range() function is expecting an integer value, however, value is actually an array

1 Like

Thank you so much for the help!

I’m pretty new to Ignition and SQL. Are there any reasons for this?

Performance on the Ignition side.

If you do it in a script transform, you’re looping through an array. Better if you can just return the information from SQL the way you need it.

Plus the overhead of running a jython script, which is not free.

1 Like