Passing an integer value from a script to report doesn't work

Hello,

I'm new to Ignition and I have an issue with reporting.

I have a report with Basic SQL Query as Data source:

SELECT audit_events.
FROM audit_events
WHERE AUDIT_EVENTS_ID = :idValue

In project I choose idValue using Spinner component and pass it to a Button with a script attached to actionPerformed Event Handler to generate the report:

selected_id = event.source.parent.getComponent('Spinner').intValue

settings = {"path":"C:\\Users\\kreek\\Desktop", "fileName":"Report.pdf", "format":"pdf", "idValue": selected_id}

system.report.executeAndDistribute(path="Audit Report", project="EFi", action="save", actionSettings=settings)

And the report comes out blank, without any data for some reason.

I also just for testing i tried it with
WHERE Date < :selectedDate

Where selectedDate was a date from calendar component and it worked flawlessly.

Am i missing something?

If you look at the function signature in the manual, you'll see that parameters are not included in the action settings.

selected_id = event.source.parent.getComponent('Spinner').intValue
parameters= {"idValue": selected_id}

settings = {
    "path":"C:\\Users\\kreek\\Desktop", 
    "fileName":"Report.pdf", 
    "format":"pdf"
}

system.report.executeAndDistribute(
    path="Audit Report", 
    project="EFi", 
    action="save", actionSettings=settings, 
    parameters=parameters
)
2 Likes

Unfortunately that didn't fix the issue :frowning:

My current script:

selected_id = event.source.parent.getComponent('Spinner').intValue
print selected_id

pars = {"idValue": selected_id}

settings = {
			"path":"C:\\Users\\kreek\\Desktop",
			"fileName":"Report.pdf",
			"format":"pdf"
			}

system.report.executeAndDistribute(
path="Audit Report",
project="EFi",
action="save",
actionSettings=settings,
parameters=pars)

My current Query:

I'm completely stuck. Hard-coding a value into a query works perfectly, but getting it from a component is not working for me at all.

You are not using your parameter at all because it does not exist. You have to create the parameter, idValue in the report, not just the query.

image

Example for Named Query source

For query source, you use a ? for the variable place holder, not the named query style :intValue. After you put in a question mark, a window will appear to choose the parameter to substitute into the query.

2 Likes

Solved! Thank you very much!

For anyone else wondering in the future:

I just had to add an empty parameter idValue:

and change the way the parameter is being put in the query from
WHERE AUDIT_EVENTS_ID = :idValue
to
WHERE AUDIT_EVENTS_ID = {idValue}

Just to clarify, it does not need to be empty. If you supply a value in the report, it will be the default value if an overriding parameter is not used in the report execute function.

1 Like