Dynamic Reporting issue send mail based on day selection

import system
from time import sleep
from time import localtime, strftime
curTime = strftime("%H:%M:%S", localtime())

if  "02:06:00" < curTime < "02:07:00":

i am using dynamic reporting
this is the script running in gateway timer

this script sending mail at particular time daily

what i am trying is ,when user select monday, tuesday or any one day in week. that day only i want to email report instead of sending report daily

can any one please help me out

Hi @prasath.t, can you use %A to get the weekday name and check for this in your first if statement?

You may also be interested in the future 8.1.6 release, as this contains cron-based scripting event.

Also, slight note on using sleep in scripts. It can be considered bad practice in locking the thread with sleep (see here for further information). Although, in your case it’s a Gateway scoped script, so might not be so much of an issue. Just a minor observation :slight_smile:

2 Likes

Thanks for the reply
in which statement i have to use and check?
I never used %A is there any documentation available or please mention in my script how to use the %A

No worries @prasath.t. Could you try something like this?:

curTime = strftime("%A %H:%M:%S", localtime())

if  "Monday 02:06:00" < curTime < "Monday 02:07:00":
...

Haven’t tried it personally, so I’m not sure if it will work with localtime(). This is the documentation I was using for reference.

If the above doesn’t work you may have better luck with datetime

1 Like

Thanks i will try this out

1 Like

Its working i checked thanks

but if user select multiple days , how to given in if condition
is there any option available?

please if you find any option let me know

No worries @prasath.t. You could pass your selected days in a list format, for example:

selectedDates = ['Tuesday, Sunday']

Then separate out the day from the previous example:

curDay = strftime("%A", localtime())
curTime = strftime("%H:%M:%S", localtime())

Then check the day in your main script:

if  curDay in selectedDates:
	if  "02:06:00" < curTime < "02:07:00":
		# Do something

There is probably a better way of doing it, but that’s the best I can think of at the moment :slight_smile:

1 Like

That’s a good point @prasath.t! I completely forgot the main script was in a Gateway script.

You can’t directly pass the values to the Gateway script, but you could save the selected dates to a database or a memory tag for the script to query/read.

OK thanks will implement and check

Hi, i have stored the days(example - monday, tuesday…) in database table as list


there are 6 rows in tabel
gateway script will excute 6 time because i have for loop for row

i tired to run the query and printed its showing rows and column numbers only
but i want selected column value to my list
selectedDates = [‘Tuesday, Sunday’]
this should change dynamically depends upon the value in select_day column values in database

so when loop runs 6 times selectedDates = [‘Tuesday, Sunday’] this list should change dynamically based the row value in select_day column in database

i tired but i couldn’t able to find solution

please help me out in this

Hi @prasath.t, you should be able to format the ‘select_day’ as JSON assuming it is stored in the database as a string and it has the correct JSON structure (which it looks like it does).

This can be done by using system.util.jsonDecode.

jsonString = system. file .readFileAsString( “C:\tmp\json.txt” )

they mentioned the path. in my script how to call the database column like this ?
please give example in my script
i am trying change the list path dynamically based the row data

system.db.runScalarQuery

Something like (you will have to fix the syntax to match the type of DB you’re using, I’m only familiar with MSSQL :sweat_smile:):

rr = system.db.runScalarQuery("SELECT select_day FROM DatabaseName WHERE Id=SomeID")

Note that runScalarQuery expects only 1 row and column to be returned. Alternatively, you can use runQuery (like in your example) and loop through the results to get the column value for each row.

rr = system.db.runScalarQuery(“SELECT select_day FROM DatabaseName WHERE Id=SomeID”)

yes its working in my database also

loop through the results to get the column value for each row. any example loop through to get the row dynmaically?

Just for my understanding, lets backup a step. Are you aiming to loop through and get all the dates in a list and then run the report once, or are you looking to loop through and run the report for each row returned?

Sorry, just want to make sure I understand the issue fully :slight_smile:

for each row in the table

**for row in table:**
**	if  curDay in selectedDates:**

each row has different day details
one row has Monday and Wednesday
second row has Friday and Sunday

based the on the list data loop runs if present day not in the list .it will stop and runs the second row and check its matching means it will mail the data

it will check each row

hope i explained you clearly?

Thank you :slight_smile: I thought that was the case, I just wanted to make sure.

Something like this could work:

rr = system.db.runQuery('SELECT select_day FROM TableName WHERE SomeCondition)
selectedDates = system.dataset.toPyDataSet(rr)

for row in selectedDates:
	selectedDays = system.util.jsonDecode(row["select_day"])

	if curDay in selectedDays:
		# Do Something
1 Like

if curDay in selectedDays: in this line getting error

Traceback (most recent call last):
File “”, line 7, in
TypeError: ‘NoneType’ object is not iterable

@prasath.t your dataset has some null values in it. You will also have to check if row[“select_day”] is not null.

1 Like

got it selectedDays = str(system.util.jsonDecode(row[“select_day”]))

we have to use str

now its not showing error