[00:00]
Let's take a look at some of the scripting functions available for the reporting module. We have this very simple report named script report, which just shows this parameter, function name as a text field. If we take a look at the data tab, we'll see that function name is just an empty string. We're going to go ahead and use this report in a couple of scripting examples. To start we'll come to the execute report window in my project browser. Now, this window has an empty PDF view and this button. Let's open up the button script by right clicking into the scripting menu. You can see we're using system dot report dot execute report. This function executes a specified report and then it returns a byte array of the report. You can do all sorts of things with these bytes, like store them in your database or pass them directly into the PDF viewer, which is what I'm going to do here. When using this function, you need to specify the path, so this is the path in the project browser to the report.
[01:04]
Next, you pass the project name that the report resides in, and then you can override any parameters. In this case, we are overriding the function name parameter, and then you need to specify a format. The way we're getting the report into the PDF viewer is with this load bytes PDF function. Let's click okay and put the designer into preview mode. We'll click the button and there's the report. And as you can see, our parameter has been overridden and it's showing up on our report. Next, let's take the designer out of preview mode. We'll head over to my execute and distribute window, and we'll take a look at this execute and distribute button. We'll right click on it and take a look at the script. The script is using system dot report dot execute and distribute. Similar to the execute report function, execute and distribute does execute the report Additionally, it distributes the report so you can email, print, save to an FTP server or save the report locally.
[02:07]
Now this happens immediately so you can have your users run an action on a report without needing them to enter the designer. Now remember, reports run in the gateway, so when you call a save action like this, it's going to be relative to the gateway. So what we're doing here is specifying which report to execute, the script report again, and the project name for the project containing the report. I'm overriding my parameter, my function name parameter here. There's an action argument that's just saying I want to save this report. And then there's some action settings. Now the action settings are going to be different depending on whatever action you're using here. So the action settings for save would be the path to wherever I want the file to be saved, whatever I want the file to be named, and then what format I want to save it in. So let's see the button in action. We'll click okay. Let's move the designer out of the way a little bit so we can watch my reports folder, which is where I want the report to save.
[03:08]
Let's go into preview mode and click our button. We can see the report was saved, and we'll open this up and here's our report. Again, we can see our parameter was overridden. We'll close this out and maximize our designer. I'm going to take the designer out of preview mode. Let's move on to our last example in the get report names window. On this window we have an empty tree view component and a report viewer component. Let's right click into the scripting option. For our button, we see the function system dot report dot get report names as dataset. This function returns a data set of report paths and names for the specified project. So we see on line two, I'm gathering the project name and then I'm passing the project to the function. With this data set of report names, I could then use this on a number of components that are driven by a data set. In this case, I'm populating the tree view items with the data set of report names on line eight.
[04:05]
I'm also filtering the data set to only give the text and selected text columns. Let's go ahead and click on, okay, we'll go to preview mode and click on our button and we can see the tree view now has all of my projects reports listed, and I have these values bound to the report path on my report viewer, so they can all be viewed from the client. There's also a similar function available system.report, dot get report names as list, which instead of returning a dataset, returns a list of report paths for the project. One last function I would like to mention is on the report viewer itself, so we'll go back into design mode and right click into the scripting option. We see the extension function on report generated. This is triggered every time the report is generated, so changing the report path, for example, would trigger it. Changing a parameter on the report viewer component, that would trigger it too. So say for example, you wanted to use our message handlers to let everyone know our report's been generated or write to a tag when our report's been generated, or something to that effect, you can go ahead and do that right here.