Dynamic Reporting issue send mail based on day selection

That doesn’t seem correct to me.

row[“select_day”] should ideally be a JSON string.

system.util.jsonDecode(row[“select_day”]) should convert it to a list format implicitly (I think).

Putting str() in just converts it back to a string.

1 Like

i have one issue in first step of adding days to database

when user select days (ex - monday and tuesday) and click add to scheduled button it will write to the database

when they again choose other day(monday) and add click add to scheduled button will add day to 2 second row of the database

if event.source.parent.getComponent('CheckBox').selected and event.source.parent.getComponent('CheckBox 1').selected and event.source.parent.getComponent('CheckBox 2').selected :

	sel = "[" + event.source.parent.getComponent('CheckBox').text + "," + event.source.parent.getComponent('CheckBox 1').text + "," + event.source.parent.getComponent('CheckBox 2').text + "]"
elif event.source.parent.getComponent('CheckBox').selected and event.source.parent.getComponent('CheckBox 1').selected:
	sel = "[" + event.source.parent.getComponent('CheckBox').text + "," + event.source.parent.getComponent('CheckBox 1').text + "]"
elif event.source.parent.getComponent('CheckBox').selected and event.source.parent.getComponent('CheckBox 2').selected :
	sel = "[" + event.source.parent.getComponent('CheckBox').text + "," + event.source.parent.getComponent('CheckBox 2').text + "]"

my using this scripts by trying different possibilities but if i do like this i have to write 200 to 300 lines for all the possibilities from monday to sunday

is there any other option to add day list to database depends upon the user selection?

You could use a for loop and string concatenation to do this. For example:

# Create a list of all the checkbox component names
checkboxes = ['Checkbox', 'Checkbox 1', ...]

# Initialise the string
sel = "["

# Loop through the checkboxes and add the days if required
for i, cb in enumerate(checkboxes):
    checkbox = event.source.parent.getComponent(cb)
    
    # Check if it's selected
    if checkbox.selected:
        if i == 0:
            # First iteration so don't include comma
            sel = sel + checkbox.text
        else:
            # All other interations include comma
            sel = sel + ", " + checkbox.text

# Close the list at the end of the concatenation
sel = sel + "]"
        

There might be a more efficient way to do this, but it’s the best I could come up with for now :slight_smile:

1 Like

Thanks for your support for past 2 days. I learnt many things from you

1 Like

fyi, instead of doing this, you could use join. There are many ways to eat sushi of course :slightly_smiling_face:

sel_cboxes = [] 
if checkbox.selected:
    sel_cboxes.append(checkbox.text)
sel += ', '.join(sel_cboxes)

#
2 Likes

Hi @prasath.t, if you are looking to replicate this Outlook functionality, this will be a large undertaking with many ways to do it. This will have to be something you work through yourself based on your coding style and what your exact requirements are.

I/we are happy to help/advise with specific issues, but providing full methodology of how to get bespoke project features implemented is a little out of scope. Almost all of us on here are doing this in our spare time and just drop in form time-to-time to answer a few questions :slight_smile:

3 Likes

hi, @matthew.ayre

i have to 2 list

currentday = [‘Fri May 07 00:00:00 IST 2021’]

listfromdatabase= [‘Fri May 07 00:00:00 IST 2021’, ‘Wed May 05 00:00:00 IST 2021’]

if currentday in listfromdatabase:
if i give like this loop is not executing
if currentday == listfromdatabase:
if i give like this loop is not executing (this also not executing)
i just wan to compare current dat with list from database if its matching i want to execute the loop

anything i have did wrong here?

my script

import system
from time import sleep
from time import localtime, strftime
#curTime = strftime("%A %H:%M:%S", localtime())
#rr = system.db.runQuery('SELECT "select_day" FROM ems_report_schedule')
#selectedDates = system.dataset.toPyDataSet(rr)
#selectedDates = rr
a =strftime("%a %b %d 00:00:00 IST %Y")
yy = [a]
print yy
curDay = strftime("%A", localtime())
curTime = strftime("%H:%M:%S", localtime())
table = system.db.runQuery("SELECT * from ems_report_schedule where reporting_interval = 'Day'",'SG_OT_Historian')
for row in table:
	selectedDays = str(system.util.jsonDecode(row["month"]))
	print selectedDays
	if  str(yy) in str(selectedDays):

Hi @prasath.t, is this the part causing the issue?:

table is a dataset type, not a list type. Please see here on how to iterate through datasets correctly. I would recommend using a pyDataset as they are easier to manipulate.

No its in if statement i tired without for loop also

currentday = [‘Fri May 07 00:00:00 IST 2021’]

listfromdatabase= [‘Fri May 07 00:00:00 IST 2021’, ‘Wed May 05 00:00:00 IST 2021’]

if currentday in listfromdatabase:
if i give like this loop is not executing
if currentday == listfromdatabase:

like this… still loop not executing

currentday = ['Fri May 07 00:00:00 IST 2021']
listfromdatabase =['Fri May 07 00:00:00 IST 2021','Wed May 05 00:00:00 IST 2021']

if currentday in listfromdatabase:
    print 'Found Current Day'
else:
    print 'Current Day not Found'

if currentday[0] in listfromdatabase:
    print 'Found Current Day'
else:
    print 'Current Day not Found'

Run this code in the script console and look at what prints out. Look at the code and try to reason out why it works the way it does.

In your first example if currentday in listfromdatabase: is false because currentday is a list and listfromdatabase is a list of strings, none of the elements in listfromdatabase is a list with 1 element equal to 'Fri May 07 00:00:00 IST 2021'.

In your second example if currentday == listfromdatabase: is false because the list currentday is not equal to the list listfromdatabase.

In my example, when you look for the string 'Fri May 07 00:00:00 IST 2021' the statement will evaluate to true. I illustrated this by using [] notation to return the 0th element of the list currentday.

The proper way to write this code is to make currentday a string and then see if it is contained in listfromdatabase. Notice the lack of square brackets in the currentday declaration.

currentday = 'Fri May 07 00:00:00 IST 2021'
listfromdatabase = ['Fri May 07 00:00:00 IST 2021','Wed May 05 00:00:00 IST 2021']

if currentday in listfromdatabase:
    print 'Found %s in listfromdatabase' % currentday
else:
    print 'Current Day not found'
4 Likes

Better yet would be to compare dates, not string versions of dates

6 Likes