In Sage X3, Crystal Reports can be generated from code, including passing parameters as variables to the Crystal Report, and defining the output location of the report. This can be useful in generating reports with different parameters on the fly, saving them to a predetermined location, and also creating from 3rd party applications, using X3 Web Services.
The following blog will provide instructions on how to make several customizations to override the Crystal Report parameters:
- Calling Crystal Report from Sage X3 4GL Code
- Overriding/providing the parameters for the Crystal Report from 4GL Code
- Overriding the output destination of the Report to a PDF in a specific directory location
- Creating a web service to generate the Crystal Report from an external source
Overriding Output File Name and Location
A Crystal Report is created using the Crystal Report tool, and defined in Sage X3 (Development > SCRIPT DICTIONARY > Reports). In the example below, the standard Quality record report definition (FICQUAL) was modified to include a new parameter called "filnam". This parameter is used to override the output location for the report. At execution time, the 4GL code will provide a value for "filnam". This will include the directory and file name, and as a result, the file will be created in the specified directory, with the name provided.
In order to accomplish this, "Specific script" must be provided to override the original parameters, and to populate the filnam parameter. In the screen below, you can see the specific script has a value of YFICQUAL.
Executing Crystal Report from Code
Below is the X3 4GL code to all the Crystal Report. The subprogram receives the parameters for the report, and populates the parameter names (TBPAR) vand value (TBVAL) with the appropriate values. The FILNAM value is the full path for the report to be generated. The YPRTR refers to the print destination (Setup > DESTINATIONS > Destinations).
##############################################################################################################
# PRINTRPT - Print Crystal Report
##############################################################################################################
Subprog PRINTRPT(QCNUM, SITENO, FILNAM, AQTY)
Value
Char QCNUM # QC Number
Value
Char SITENO # Site
Value
Char FILNAM # Output File Name
Value
Decimal AQTY # Quantity
Local
Char
FONCTION
Local
Char TBPAR(150) (150)
Local
Char TBVAL(150) (150)
Local
Char
ETAT
TBPAR(0) ="analysedeb"
TBVAL(0) = QCNUM
TBPAR(1) ="analysefin"
TBVAL(1) = QCNUM
TBPAR(2) ="stofcydeb"
TBVAL(2) = SITENO
TBPAR(3) ="stofcyfin"
TBVAL(3) = SITENO
TBPAR(4) ="infolot"
TBVAL(4) = "1"
TBPAR(5) ="flgrgp"
TBVAL(5) = "2"
TBPAR(6) ="impselections"
TBVAL(6) = "2"
TBPAR(7) ="filnam"
TBVAL(7) = FILNAM
TBPAR(8) ="aqty"
TBVAL(8) = num$(AQTY)
GSERVEUR = 1
GSILENCE = 1
ETAT = "YFICQUAL"
Call ETAT(ETAT,"YPRTR","eng",0,FONCTION,TBPAR,TBVAL) From AIMP3
End
Print Destination
In the sample code above, the printing of the Crystal Report included a destination code. Below is the definition for the destination. Notice that the output type is "File", and the export format is "PDF". This will generate a physical file, with a type of PDF, for the Crystal Report.
Crystal Report-Specific Code
The final part required to override the file location and name is the Specific Code YFICQUAL, as specified in the Report Dictionary definition. When the print is execution, and the FICHIER Action started, the parameter name for the file name is captured, and the parameter FICHIER (File) is overridden with this value.
$ACTION
Case ACTION
When
"FICHIER" : Gosub FICHIER
When
Default
Endcase
Return
$FICHIER
If GSERVEUR = 1
If
dim(FICHIER)
Local
Integer YTEMP
# Find the parameter named filnam, and override the report file name with this value
For YTEMP = 0 To 10
If [M:AIP]TBPAR(YTEMP) ="filnam"
FICHIER = [M:AIP]TBVAL(YTEMP)
Break
Endif
Next
Endif
Endif
Return
Publishing as a Web Service
If desired, the above functionality can be wrapped up in a subprogram, and published as a web service. This allows the Crystal report to be generated for an external programming language or application using Sage X3 web services.
Summary
In summary, we have demonstrated several ways to generate and print Crystal Reports from within the Sage X3 4GL, including:
-
- Programmatically generating the Crystal Report from X3 4GL Code.
- Overriding the report name and directory from X3 4GL Code
- Creating a web service to generate the Crystal Report.
Be sure to contact us with your questions or for help with Crystal Reports in Sage X3.
I Need X3 Support »