# Execute report based on tag value

**URL:** <https://forum.inductiveautomation.com/t/execute-report-based-on-tag-value/59249>\
**Category:** Ignition\
**Created:** [May 5, 2022, 1:14pm UTC](https://forum.inductiveautomation.com/t/execute-report-based-on-tag-value/59249 "2022-05-05T13:14:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Rodriguez](https://avatars.discourse-cdn.com/v4/letter/d/b5e925/32.png) [@David\_Rodriguez](https://forum.inductiveautomation.com/u/David_Rodriguez)\
**Post date:** [May 5, 2022, 1:14pm UTC](https://forum.inductiveautomation.com/t/execute-report-based-on-tag-value/59249/1 "2022-05-05T13:14:27Z")

</div>

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:

```auto
	#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,

David

---

<div class="post-metadata">

**Author:** ![David\_Rodriguez](https://avatars.discourse-cdn.com/v4/letter/d/b5e925/32.png) [@David\_Rodriguez](https://forum.inductiveautomation.com/u/David_Rodriguez)\
**Post date:** [May 5, 2022, 1:35pm UTC](https://forum.inductiveautomation.com/t/execute-report-based-on-tag-value/59249/3 "2022-05-05T13:35:22Z")

</div>

Edited, thank you!

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 5, 2022, 1:48pm UTC](https://forum.inductiveautomation.com/t/execute-report-based-on-tag-value/59249/4 "2022-05-05T13:48:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![David\_Rodriguez](https://avatars.discourse-cdn.com/v4/letter/d/b5e925/32.png) [@David\_Rodriguez](https://forum.inductiveautomation.com/u/David_Rodriguez)\
**Post date:** [May 5, 2022, 2:18pm UTC](https://forum.inductiveautomation.com/t/execute-report-based-on-tag-value/59249/5 "2022-05-05T14:18:17Z")

</div>

Oh thank you! I will give it a go.
