Creating an expression Tag

Hello, so i’m trying to output the right shift(A,B,C) based on the time of the day so i created an expression tag and changed it to string and in the expression field i put :

if dateExtract(now(0),"hour") >= 7 && dateExtract(now(0),"hour") < 15:
	print 'A'
elif dateExtract(now(0),"hour") >= 15 && dateExtract(now(0),"hour") < 23:
	print 'B'
else: 
	print 'C'

What am i doing wrong? doesn’t “dateExtract(now(0),“hour”)” extract the hour of the day?
Whats weird is this mostly works fine when i try it in script playground and change the “dateExtract(now(0),“hour”)” to a variable x and give it a value. Thanks

It looks like you are on the right track using expression functions. “If” functions work differently in expression language than they do in Python/Jython.

To handle the three different possibilities you will have to use nested functions.

if(dateExtract(now(0),"hour") >= 7 && dateExtract(now(0),"hour") < 15, 'A', if(dateExtract(now(0),"hour") >= 15 && dateExtract(now(0),"hour") < 23 , 'B' , 'C' ) )

The second if function goes in the “falseReturn” part of the outer if function.

support.inductiveautomation.com … gic_if.htm

wow, thank you. I was sitting here trying to figure it out and suddenly hits me that wait a min, don’t think python commands will work the same with expressions and that’s why it worked in the playground not in the tag expression. again, thanks for the reply! :thumb_right: :thumb_left:

You’re welcome!

:thumb_right: :afro: :thumb_left:

another question, might as well give a brief explanation, i have 6 tags, one being the shifts that you helped me figure out earlier, i made a transaction group and put these 6 tags in it so i can make a customized table, everything is good, I’m trying to add some options here, one being adding a drop down calendar and have the user pick the date interval they want to see the data for. this is the query i try:

SELECT 
	Part_Number, 
	Running_Percentage, 
	Time_Percentage, 
	Cycle_Time, 
	Over_seconds, 
	t_stamp, 
        twelve_hour_Shifts 
FROM JK_LH_Monthly

WHERE 
        t_stamp BETWEEN {Root Container.Start.date} AND {Root Container.End.date};

and it doesn’t seem to work, i keep getting an error saying

Exception: Error running query:
SQLQuery(query=SELECT
	Part_Number, 
	Running_Percentage, 
	Time_Percentage, 
	Cycle_Time, 
	Over_seconds, 
	t_stamp, 
        twelve_hour_Shifts 
FROM JK_LH_Monthly

WHERE 
        t_stamp BETWEEN 2015-06-16 16:19:04 AND 2015-06-23 16:19:04;
, database =)@5000ms
on: JK_LH_Month.root container.Table.data
        caused by GatewayException: incorrect syntax near '16'.
        caused by SQLServerException: incorrect syntax near '16'.

What am I doing wrong? i thought that’s how you are suppose to use “BETWEEN” also, what does ‘16’ represent? line? character? Thanks in advance :mrgreen:

Hi there,

Try adding single quotes around your dates, like this:

WHERE
        t_stamp BETWEEN '{Root Container.Start.date}' AND '{Root Container.End.date}';

16 represents the number 16 in your date.

umm, yeah of course it would be that easy :open_mouth: … thanks a lot. its working now.

Now is it possible to make sure table opens up in client to the last row(most recent), when it opens now its always at the oldest row all the way at the top, i want it all the way at the bottom.

This ought to do it. It would go in the table’s property change event

if event.propertyName == "data" and event.newValue is not None:
    table = event.source.parent.getComponent('Table')
    table.selectedRow = event.newValue.rowCount - 1

Thanks, that does work but i ended up changing it back since if for some reason I want to go up and look at a certain date it jumps right back the most recent date. but it worked Thanks.

I wrote this Query that to select data for my table from two popup calender

SELECT 
	t_stamp,
	Part_Number, 
	Running_Percentage, 
	Time_Percentage, 
	Cycle_Time, 
	seconds_for_current_part, 
	twelve_hour_Shifts 

FROM JK_LH_Monthly

WHERE
    t_stamp BETWEEN '{Root Container.Group 3.Start.date}' AND '{Root Container.Group 3.End.date}';

I would like to be able to pick a date and when picked have it show data from 7am to 6:59am next day(that’s how the shifts are 7am-7am), that way when i pick say June 23rd, i see everything from 7am on 23rd to 6:59am to 24th.
I assume it works almost the same as above only difference would be in the WHERE clause but i cant use any functions. how about something like this:

WHERE 
     {Root Container.Day.date}

but maybe use the MAKETIME(07,00,00) function so its picks the day and make the time 7am

I’m still very new to SQL and learning as I go. :study: :scratch:

I know how to use dateArithmetic(date, - 7, “day”) which basically makes one date 7 days before the other but don’t know how i can do that and also tell it to make the hour, min, sec to a certain time i want.

You could add a custom property to each popup calendar and link it to an expression that reads the date and then adds on whatever time you want.

For example for the start date, add a string custom property called ‘datetime’ to the calendar and bind it to the following expression:concat(dateFormat({Root Container.Group 3.Start.date}, "yyyy-MM-dd"), " 07:00:00")Do the same for the end date with a time of “06:59:59”. You can then use these properties in your SQL expression i.e.WHERE t_stamp BETWEEN '{Root Container.Group 3.Start.datetime}' AND '{Root Container.Group 3.End.datetime}';