Print Page | Close Window

.NET questions

Printed From: Crystal Reports Book
Category: Crystal Reports .NET 2003
Forum Name: Writing Code
Forum Discription: .NET 2003 programming API, report integration
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=22864
Printed Date: 03 Jul 2022 at 10:02am


Topic: .NET questions
Posted By: hello
Subject: .NET questions
Date Posted: 12 Mar 2020 at 5:02am
Hello:

I was hoping there where a few .NET gurus here that could help me understand some basic programming using the CRYSTALDECISIONS.SHARED and CRYSTALDECISIONS.ENGINE assemblies.

First off, here is my Powershell code to load a report, set parameters, and then displays the parameters for viewing on the screen.


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

$report = New-Object CrystalDecisions.CrystalReports.Engine.ReportDocument
$report.Load("C:\TEMPLATE.rpt")


#hard code prompted values here
$customer = '065447'
$location = 1000
$locationsToExclude = 0
$range = New-Object CrystalDecisions.Shared.ParameterRangeValue
$range.StartValue = 1
$range.EndValue = 999

#main report parameter mapping
$report.SetParameterValue("Parent",$customer)
$report.SetParameterValue("Location",$location)
$report.SetParameterValue("@LocationsToExclude",$locationsToExclude)
$report.SetParameterValue("LocationRange",$range)

#sub reports parameter mapping
$report.SetParameterValue("Pm-SHIPMENT.PRO",'FB_Pointer.PRO')

$report.HasRecords

#$parameterField = New-Object CrystalDecisions.Shared.ParameterField

foreach ($parameterField in $report.DataDefinition.ParameterFields)
{
        write-output "The current value of:"
        $parameterField.Name
        write-output "In report:"
        $parameterField.ReportName
        write-output "is:"
        $parameterField.CurrentValues.Value
        write-output "Of kind:"
        $parameterField.DiscreteOrRangeKind
        write-output "-------------------"
}


QUESTION 1
What exactly does HASRECORDS do? If I leave out that line, the report has no data and is blank. Is HASRECORDS basically an 'execute' command?

QUESTION 2
The FOREACH loop at the end simply shows parameter values for each parameter, but the parameters on the sub report never show anything. How do I access the values of the sub reports?


Thanks for any input.



Replies:
Posted By: hilfy
Date Posted: 20 Apr 2020 at 5:47am
I haven't done this in Power Shell, however, I hope I can point you in the right direction.

1. I would replace "HasRecords" with "Refresh" to run the report.

2. To get to the parameters for the subreport, you actually have to walk through the sections of the report in code to find the subreports and pull the parameters from individual subreports just like you're doing for the main report. In fact, I'm surprised your report is even running because I don't see where you're setting the credentials for the database connections, which you also have to do for each subreport as well as the main report.

-Dell

-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics



Print Page | Close Window