Execute report based on tag value

Hi everyone,

I am trying to generated a report based on the status of a tank, the tank is defined by a UDT which contains a tag ‘Status’. When the value of this tag is ‘1’ = Running and ‘0’ = ‘Not running’.

Whenever the tank finished with the batch run, the status of the variable ‘status’ goes automatically back to zero.

I have created a script that whenever the operator clicks on a button ‘Start’, this captures two parameters for my report in a memory tag ‘StartDate’ and ‘user’ and saves then in a memory tag.

The challenge I am facing is to call, system.report.executeAndDistribute whenever the value of tag ‘status’ of a given tank changed from 1= Running to 0= Not running.

What I have in mind is something like this:

Under Schedule in reports – Select Custom, and in Actions create a script as follows:

	#Declare variables and paths
	#Tankname = How can I make this variable dynamic? 
    #Operators select from a dropdown menu the tankname and a template displays the right info for the selected tank. 
    #I would like that the trigger action runs for any given tank.
	pathEndDate = "[default]Production/" + Tankname + "/Report/EndDate"
	pathStartDate = "[default]Production/" + Tankname + "/Report/StartDate"
	pathTanknumber = "[default]Production/" + Tankname + "/Report/Tanknumber"
	pathTanktype = "[default]Production/" + Tankname + "/Report/Tanktype"
	pathuser = "[default]Production/" + Tankname + "/Report/user"
    pathstatus = "[default]Production/" + Tankname + "/Status"

	EndDate = system.date.now()
	StartDate = system.tag.readBlocking(pathStartDate)
	Tanknummer = system.tag.readBlocking(pathTanknummer)
	Tanktype = system.tag.readBlocking(pathTanktype)
	user = system.tag.readBlocking(pathuser)
    status = system.tag.readBlocking(pathstatus)

    #Variables for the report (Parameters)

    reportParameters = {"StartDate":StartDate, "EndDate":EndDate, "Tanknumber": Tanknumber, "Tanktype": Tanktype, "user": user}

    settings ={"path":"C:\\Ignition Reports", "fileName":"Report.pdf", "format":"pdf"}

    #Here I would need to write a condition to check if the value of ‘status’ was already 1 and changed to zero. If this is true:

    system.report.executeAndDistribute(path="My Report Path", project="My Project", parameters=reportParameters, action="save", actionSettings=settings)

If the condition is false it should loop until this becomes true. Any idea on how to set this condition?

The condition needs to be evaluated for every tank (we have 5 identical tanks working with UDTs).

Alternatively, I was thinking that perhaps I can add 5 different schedules, set them all to custom, and pass a tankname parameter to them. So that the script knows into which UDT to look for the values, and in the actions set a script with the condition that I still need to figure out how to define.

Would anyone be so kind to point me into the right direction?

Thanks in advance,


Edited, thank you!

Don’t schedule the report. Use a tag change event to to trigger report generation. See system.report.executeAndDistribute.

Oh thank you! I will give it a go.