Writing Code
 Crystal Reports Forum : Crystal Reports .NET 2003 : Writing Code
Message Icon Topic: .NET questions Post Reply Post New Topic
Author Message
hello
Groupie
Groupie
Avatar

Joined: 05 Feb 2014
Online Status: Offline
Posts: 85
Quote hello Replybullet Topic: .NET questions
    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.
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet 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
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.029 seconds.