# Issues with setting an Integer to an Index in an Instance

**URL:** <https://forum.inductiveautomation.com/t/issues-with-setting-an-integer-to-an-index-in-an-instance/61698>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [July 8, 2022, 9:59pm UTC](https://forum.inductiveautomation.com/t/issues-with-setting-an-integer-to-an-index-in-an-instance/61698 "2022-07-08T21:59:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![CMuecke](https://avatars.discourse-cdn.com/v4/letter/c/df705f/32.png) [@CMuecke](https://forum.inductiveautomation.com/u/CMuecke)\
**Post date:** [July 8, 2022, 9:59pm UTC](https://forum.inductiveautomation.com/t/issues-with-setting-an-integer-to-an-index-in-an-instance/61698/1 "2022-07-08T21:59:34Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/2/22d43af16b6b2ec86177115f0b073761e9e76e3a.png)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 9, 2022, 3:48pm UTC](https://forum.inductiveautomation.com/t/issues-with-setting-an-integer-to-an-index-in-an-instance/61698/2 "2022-07-09T15:48:38Z")

</div>

> [@CMuecke](#):
>
> 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.

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:

```python
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)

---

<div class="post-metadata">

**Author:** ![CMuecke](https://avatars.discourse-cdn.com/v4/letter/c/df705f/32.png) [@CMuecke](https://forum.inductiveautomation.com/u/CMuecke)\
**Post date:** [July 11, 2022, 12:29pm UTC](https://forum.inductiveautomation.com/t/issues-with-setting-an-integer-to-an-index-in-an-instance/61698/3 "2022-07-11T12:29:21Z")

</div>

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](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/8/d8953877bb2174568981cc61552f5ae437d8ce32.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/e/9e1a2d63150143ca97d95652102b3d6acd8e606e.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/9/5925babd2c4c08d705b58cffc61f77b881f5e416.png)  
 ![Error Code](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/8/b86c13b7b2187b02742eeea718c9e70abea7edb6.png)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 11, 2022, 12:52pm UTC](https://forum.inductiveautomation.com/t/issues-with-setting-an-integer-to-an-index-in-an-instance/61698/4 "2022-07-11T12:52:54Z")

</div>

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:

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

```

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

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 11, 2022, 12:53pm UTC](https://forum.inductiveautomation.com/t/issues-with-setting-an-integer-to-an-index-in-an-instance/61698/5 "2022-07-11T12:53:43Z")

</div>

I would be tempted to do something like:

```nohighlight
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.

```nohighlight
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

---

<div class="post-metadata">

**Author:** ![CMuecke](https://avatars.discourse-cdn.com/v4/letter/c/df705f/32.png) [@CMuecke](https://forum.inductiveautomation.com/u/CMuecke)\
**Post date:** [July 11, 2022, 1:37pm UTC](https://forum.inductiveautomation.com/t/issues-with-setting-an-integer-to-an-index-in-an-instance/61698/6 "2022-07-11T13:37:34Z")

</div>

Thank you so much for the help!

---

<div class="post-metadata">

**Author:** ![CMuecke](https://avatars.discourse-cdn.com/v4/letter/c/df705f/32.png) [@CMuecke](https://forum.inductiveautomation.com/u/CMuecke)\
**Post date:** [July 11, 2022, 2:28pm UTC](https://forum.inductiveautomation.com/t/issues-with-setting-an-integer-to-an-index-in-an-instance/61698/7 "2022-07-11T14:28:08Z")

</div>

> [@pascal.fragnoud](#):
>
> edit: Do what @lrose said, add the index in your query.

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

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 11, 2022, 2:32pm UTC](https://forum.inductiveautomation.com/t/issues-with-setting-an-integer-to-an-index-in-an-instance/61698/8 "2022-07-11T14:32:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 11, 2022, 2:58pm UTC](https://forum.inductiveautomation.com/t/issues-with-setting-an-integer-to-an-index-in-an-instance/61698/9 "2022-07-11T14:58:51Z")

</div>

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