I am trying to apply color to a component based on the returned value of a named query (in this case date) I wrote my script as is suggested by the ignition manual however I get a syntax error. This script should work but I cannot figure out why it is not working. I wrote this script on the expression binding of a color property. My “test.DateQuery” is also a property.
Your expression will treat 2 dates the same as 1 date, or 1000. ANY value returned from the query ( including 0 rows!) is non-null.
Not exactly sure what you are trying to capture, but if you are looking to differentiate between 1 result and multiple results then you may need to check the length of the query result; ie if(len({test.DateQuery})!=1,color(255,0,0),<other color>)
Thank you so much Dustin!
That seems to be working. However, the color changed to red but it remains unchanged if the date is null or not null.
I did see a difference only. When the date is not null I get this f(x) at the top!
What I am trying to do is that I am trying to change the color property of the component based on a returned value of the named query (my date value). The returned date can be one value or multiple values.
The f(x) overlay is because your query is null, and indicates bad quality. If you want to avoid this, you can check “overlay opt-out” on the binding of the component value. This will remove that bad quality overlay when the query result is null.
If you want to change the color of the component based on the value returned, regardless of the number of values returned, then you will need that logic in your if() expression. However, if you have multiple potential values from your query, then you might need a script transform to parse through your values for the one you want to compare against.
Thank you very much, Dustin. Appreciate your help.
The thing is when my query returns no row I get an error.
“Named Query returned no rows on component”
Even though I turned on that overlayOPT option, I do still get the error.
If I want to be specific:
I have a named query with two parameters. I get those two parameters from two tags. If my query returns no row I want a color property to be red otherwise if it returns at least one row I want the color to be yellow.
This is what I am doing. I have a template called “test” and I have a named query with two parameters and I get the value of the parameters from two memory tags.
The template has an internal property called DateQuery and its data is bound to that named query.
I have the expression on the background color of my template. The DateQuery can return multiple rows or no rows.
Yes, This Works but I am getting a result where length of the Dataset is 1 but it doesnt holds any value, so here how can we check? If I am checking with isNull its not giving the proper result as well
len({Root Container.Power Table.data}) will produce a value of 1 because the length of the dataset is one element, but if I spot check the first row of the first column by adding brackets to the end of the expression, I will get a value of zero because there is no actual value at [row 0, column 0]: `len({Root Container.Power Table.data}[0,0])