Dataset to string index syntax issue. Help please!

Hi

I’m new to Ignition so this is probably a very basic problem. Ignition v7.9.

I have put together a simple template called ‘Analogue_Input_UDT’. The intended function is to display the analogue input in a numeric label and to display the tag name in a label above. The numeric indicator works perfectly. However, I’m struggling to extract the tag name from an address that is pushed to my template.

For example, “PASTE/Analogue Input/A16LT001” is my input path (TagPath) and I wish to extract the “A16LT001” string.

The following expression returns the string “PASTE” as expected.

split({Analogue_Input_UDT.TagPath},"/")[0]

If I change this to any of the following, an array out of bounds error is generated.

split({Analogue_Input_UDT.TagPath},"/")[1]
split({Analogue_Input_UDT.TagPath},"/")[1,0]
split({Analogue_Input_UDT.TagPath},"/")[1,1]

I know the result is a dataset because I have bound the split path to the data input for a table and it shows 1 column with three rows. e.g. PASTE, Analogue Input, A16LT001.

Can someone help me to return the 3rd row of the first column please? I’m sure my syntax is incorrect but I can’t work out how to fix it.

Thanks!

Array index is by row and then column. Try:

split({Analogue_Input_UDT.TagPath},"/")[2,0]

That said, if the data is as you note above, the following example should have returned “Analog Input”:

split({Analogue_Input_UDT.TagPath},"/")[1,0]

Hi

Many thanks for the reply. Yes, everything is now working.

My code was OK. The problem was that the template I was working on in designer kept throwing errors because it did not have any data. Once parameterized at run time, all instances are working fine. Thanks again. I’ll know for next time!

Best regards

1 Like

You’re welcome; glad you got it working. In templates, I find sometimes it is helpful to use try in expressions to provide a default value in the template for when editing the template. Other cases just entering a useful default value for parameters that will be bound at runtime is helpful.

Good plan. I’ll add some default values so the template doesn’t throw errors when opened. The template also has a pop-up with a chart and SQL queries which also generate errors. I’ll try to default the SQL database too so that it’s easier to work with. Thanks again.

1 Like