cancel
Showing results for 
Search instead for 
Did you mean: 

Crystal Reports with PowerShell - How can I pass powershell variable into CR parameter field?

former_member609229
Discoverer
0 Kudos

Hi all,

Just getting my feet wet with this so please bear with me. I am having some issue automating crystal reports. I would like to pass powershell variable into the crystal report parameter and then output the information as CSV. In this code snippet I just want to pass in the date information - I hard-coded the variable for now but they the same format as the crystal report parameter.

I am running Crystal Report 2013 with PowerShell 5 - The database connection is OLE DB (ADO)

[reflection.assembly]::LoadWithPartialName('CrystalDecisions.Shared') 
[reflection.assembly]::LoadWithPartialName('CrystalDecisions.CrystalReports.Engine') 

$report = New-Object CrystalDecisions.CrystalReports.Engine.ReportDocument 
$report.Load("C:\CR_test\CVC-Report-Monthly.rpt") $report.SetDatabaseLogon('account_name','password')

$report.SetParameterValue('FromDate','13/12/2018') 
$report.SetParameterValue('ToDate','13/12/2019') 

$report.ExportToDisk("Excel","C:\CR_test\cvc.xls")
$report.close()

For report without any parameter I don't have a problem exporting because I just omit setting the parameter value and go straight to exportodisk method but for ones with parameters to pass I am getting

Exception calling "exportToDisk" with "2" arguments: "Missing parameter values"

Any tips would be great appreciated! thanks for your time!

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member609229
Discoverer
0 Kudos

Hi guys,

Thanks for the comments.

Dell - I have the run-time installed. I was able to get my code to work by tweaking how my sub-report handles the parameters in crystal report. Once I had linked the parameter (since I am just using from and to date field) everything worked fine.

Don - yeah it was a long shot....

0 Kudos

FYI, we don't support using Power Shell, if you find an issue and can duplicate is in a .NET app then we can look into it...

DellSC
Active Contributor
0 Kudos

From the assemblies you're loading, it looks like you also have the Crystal for Visual Studio SDK installed. If not, you will need to have one of the runtimes install in order to be able to do this.

My experience working with the SDK has been that you can't just set the parameter values on the report with SetParameterValue(). Instead, you have to get the parameters objects from the report and set them that way. There is sample .NET code along with an explanation of the process here: https://blogs.sap.com/2016/02/17/how-to-parameters-in-crystal-reports-for-visual-studio-net/. You'll have to convert it so that you can follow the process through PowerShell, which may or may not be possible.

-Dell