Microsoft Dynamics AX development

Archive for the ‘SSRS Reports’ Category

Call two time the same report but with different design from controller class

Call two time the same report but with different design from controller class

Scenario: I have a report (MyReport) with two desing (DesignA and DesignB). The two designs are in the same report because the datasource is the the same and they are called from the same menu item.
The DesignA is always printed, but only in some cases I have to print the DesignB.

In the controller class, in the output method, I’ve added the following code:

outputMethod

 

Advertisements

Textbox hidden: remove horizontal white space

Scenario: I have two textbox on the same line. Textbox A and Textbox B. Both have an hidden expression in order to hide the textbox if empty.

Aufnahme3

If the Textbox A is empty, maintains the white space in the layout.

Aufnahme4

The solution is to insert the two textbox in a rectangle.

Aufnahme5

In this way, the space of the textbox A is removed.

Aufnahme8

SrsReportDataContractUIBuilder: Enable/disable button depend on a flag

Scenario:
I have to create a dialog with SrsReportDataContractUIBuilder with:

  • a flag “MyFlag”
  • a button “MyButton”

When the flag is active, I have to disable the button.
When the flag is not active, I have to enable the button.

Create the UIBuilder class:

class MyUIBuilderClass extends SrsReportDataContractUIBuilder
{
    MyClassNameContract       contract;
    FormBuildButtonControl    myButton;
    DialogField               myFlag;
}

In the postBuild method, initialize the dialog with the controls:

Dialog                  dialogLocal;
Form                    form;
DialogGroup             dialogGroup;
FormBuildGroupControl   groupBuildControl;

dialogLocal = this.dialog();
contract = this.dataContractObject() as MyClassNameContract;
form = this.dialog().form();

myFlag = this.addDialogField(methodStr(MyClassNameContract, parmMyFlag), 
                             contract);

dialogGroup = dialogLocal.addGroup('My group name');
groupBuildControl = dialogLocal.formBuildDesign().control(
                    dialogGroup.formBuildGroup().id());
buttonBuildControl = groupBuildControl.addControl(FormControlType::Button, 
                     'My button name');

super();

myButton.text(literalStr("A text for my button"));

//if you want to add a method for the button
myButton.registerOverrideMethod(methodStr(FormButtonControl, clicked), 
         methodStr(MyUIBuilderClass, methodForTheButton), this);

myFlag = this.bindInfo().getDialogField(this.dataContractObject(), 
         methodStr(MyClassNameContract, parmMyFlag));
myFlag.value(true);
myFlag.registerOverrideMethod(methodStr(FormChecKBoxControl, modified), 
       methodStr(MyUIBuilderClass, enableDisableMyButton), this);

buttonBuildControl.enabled(!myFlag.value());

 

In the method enableDisableMyButton:

public boolean enableDisableMyButton(FormCheckBoxControl _checkBoxControl)
{
    int ctrlId          = dialog.formRun().controlId('My button name');
    FormControl control = dialog.formRun().control(ctrlId);

    control.enabled(!_checkBoxControl.checked());

    return true;
}

 

Insert the logic to bind the UIBuilder to the contract class, in the attributes:

[
     DataContractAttribute,
     SysOperationContractProcessingAttribute(
        classstr(ReturnAcknowledgmentAndDocUIBuilderWPC))
]

Keep table group on one page

To keep table groups on the same page, the table group should look like this:

Aufnahme1

Then, select the group row and set the properties “KeepTogheter” to True.

Aufnahme2

Deploy the report.

 

Align image logo to the right

1) In the DP class find the width of the image:

Image img = new Image();
CompanyInfo companyInfo = CompanyInfo::find();
CompnayImage companyImage = CompnayImage::findByRecord(comapnyInfo);

img.setData(companyImage.Image);

salesPackingSlipHeaderTmp.LogoWidth = img.Width();

2) Add the image to the report:

2

3) Set the parameters to take the image from the dataset:

3

4) In Visual Studio set the Size property (of the image) to “Original size” (Right click on the image > Properies > Size)

5) Add the following expression in the “padding left” expression:

=CSTR(211-First(Fields!LogoWidth.value, “DataSetName”)) + “pt”

Where 211 is the maximum size (in pixel) of the image.

5
6) Deploy the report

Print logo depend on print destination

Goal: print the logo only if the print destination is the printer

First of all we need a parameter, and we declare it in the contract class as follow:

[DataMemberAttribute('printLogo')]
public boolean parmPrintLogo(UsePrintMgmt _printLogo = printLogo)
{
    printLogo = _printLogo;
    return printLogo;
}

Then, we must to modify the code of the report controller. The controller must extend the SrsPrintMgmtFormLetterController or a subclass of this.

The method to override is: SrsPrintMgmtController.outputReport()
This method executes the report for the print management setting that is currently loaded.

In this way, for every record in the print management, we control the print destination, and consequently we set the parameter for the logo visibility.

protected void outputReport()
{
    SalesConfirmContract salesConfirmContract = contract as SalesConfirmContract;

    switch (formLetterReport.getCurrentPrintSetting().parmPrintJobSettings().printMediumType())
    {
        case SRSPrintMediumType::Printer : salesConfirmContract.parmPrintLogo(NoYes::No);
        break;

        default : salesConfirmContract.parmPrintLogo(NoYes::Yes);
        break;
    }

    super();
}

If the logo visibility, depend on the type of the PrintCopyOriginal, the code to use is the following:

protected void outputReport()
{
    SalesConfirmContract salesConfirmContract = contract as SalesConfirmContract;
    switch (formLetterReport.getCurrentPrintSetting().parmType())
    {
        case PrintMgmtDocInstanceType::Copy :
	salesConfirmContract.parmPrintLogo(NoYes::No);
        break;

        case PrintMgmtDocInstanceType::Original :
	salesConfirmContract.parmPrintLogo(NoYes::Yes);
        break;
    }
    super();
}

Now, we have to use the new parameter in the report layout. We found the parameter here:
parameter

Finally, insert the following code in the layout, in the “Visibility” property on the image.
Aufnahme2

Use HTML in SSRS reports

Create a string that contains HTML code, for example:

(TableName).(MyFieldName) = ‘<span style=”font-weight:bold”>’ + custTable.AccountNum + ‘</span>’;

MyFieldName is the name of the field on the tmp table for the report’s  dataset.

Open the layout in Visual Studio. In the report add a textbox and add to the textbox the MyFieldName field.

Right-Click on the placeholder in the textbox, and then click on “Placeholder properties”.

Aufnahme8

Select “HTML – Interpreter HTML tags as styles

 

Tag Cloud