This lesson is part of the Reporting in Ignition course. You can browse the rest of the lessons below.

LESSON LIST

Autoplay Off

Supplemental Videos

LESSON

Scheduling - Run Script

Description

The Run Script action allows you to schedule a Python script. In this example we'll store a copy of our report in our database before distributing it.

Video recorded using: Ignition 8.1

Transcript

(open in window)

[00:00] The run script action allows you to add python scripting to your reports. We'll begin in the schedule tab where I already have this schedule for my report, and we'll go down and click the add new action icon to add a new run script action. The run script action is a script that runs on reporting schedule. We can see it exposes the function handle finished report, which gives you a couple of parameters. We have the report name, which is the name of the report, the path to the report in your project, the data map, which lets you access all of your data sources and parameters for the report from a PI dictionary. And the report bytes, which is just a byte array that is the report itself in the file format specified in the format selection box. Now, there's a lot you can do with the run script action. Just to give you an example, I'll go ahead and paste in a script down here. So what I'm doing here is I'm actually creating a log of every time this schedule runs. So this way I always know when my reports went out. Additionally, I'm saving a copy of the report as well.

[01:05] So if I ever need to retrieve it, I can just query my database for the byte array. So all of my database interactions are occurring up here and down below I'm just distributing the report. So in this case, I'm just saving it locally, but you could of course email this out or save it to an FTP server. Like the other actions, the run script can be executed immediately. So let's take a look at my database real quick. We'll open the database query browser tool, and we're looking at my report log table here. If I execute the select query, we see there's nothing here right now, but we'll go ahead and execute the report script. If we go back to the query tool and execute the select query, you can see my report saved to the database. So for those cases where you don't have an available scheduled action that suits your needs, like storing your report in a database, providing a special email code, or anything else you can think of, then you can use the run script action to develop your own custom actions for when the report runs.

You are editing this transcript.

Make any corrections to improve this transcript. We'll review any changes before posting them.