How to pass report name in SSRS report DP class

Hello, friends

I need to pass report name to my DP class as based on specific report chosen one of the varaibles in DP class is changing. I have tried to pass the parameter through contract class, but when I call it in DP class null reference error is returned. From the info strings I have tried to pass it seems that SrsReportDataContract contract = this.parmDataContract(); method is not passing any contract in DP class. When I try to pass str test = this.parmDataContract().parmReportCaption(); the error says that the contract class does not have such method. Method parmReportCaption is the standard method of SrsReportDataContract class. It would be nice if you could help me in this.

DP class method processReport:

public void processReport()
    {
        Query           query    = this.parmQuery();
        QueryRun        queryRun = new QueryRun(query);
        Common          cursor;
        //<GEERU>
        CompanyInfo companyInfo;
        //</GEERU>
        
        //throw error(strFmt("processReport() is %1"));
        
        SrsReportDataContract contract = this.parmDataContract();
        str test = this.parmDataContract().parmReportCaption();



        throw error(strFmt("processReport() is %1"));
        //str test = contract.parmReportCaption();
        throw error(strFmt("processReport() 2 is %1", contract.parmReportCaption()));
        switch(contract.parmReportCaption())
        {
            
            case "EBRetailLabel.A4_Shelf_68x39":
                maxcolumn = 3;
				break;
            case "EBRetailLabel.A4_Shelf_90x70_Discount":
                maxcolumn = 2;
				break;
            case "EBRetailLabel.A4_Shelf_210x148_Discount":
                maxcolumn = 1;
				break;
            case "EBRetailLabel.A4_Shelf_210x148":
                maxcolumn = 1;
                break;
            case "EBRetailLabel.A4_Shelf_72x53":
                maxcolumn = 2;
                break;
            case "EBRetailLabel.A4_Shelf_41x39":
                maxcolumn = 5;
                break;
            case "EBRetailLabel.A4_Shelf_90x70":
                maxcolumn = 2;
                break;
        }

Controller class main method:

public static void Main(Args _args)
{
RetailLabelControllerEBSkyBaltia_Ext controller = new RetailLabelControllerEBSkyBaltia_Ext();
SrsReportDataContract dataContract;
SRSPrintDestinationSettings printSettings;

controller.parmArgs(_args);
//throw error(strFmt("controller.parmArgs(_args);"));
dataContract = controller.parmReportContract();
if (dataContract)
{
printSettings = dataContract.parmPrintSettings();
if (printSettings)
{
// Download the report in pdf format.
printSettings.printMediumType(SRSPrintMediumType::File);
printSettings.fileFormat(SRSReportFileFormat::PDF);
printSettings.fileName(controller.parmReportName() + '.pdf');
}
}

//throw error(strFmt("parmReportName() is %1", controller.parmReportName()));
//EBRetailLabelContract contract;
//EBRetailLabelContract contract = contract as EBRetailLabelContract;
//contract = controller.getDataContractObject() as EBRetailLabelContract;
str reportname = controller.parmReportName();

dataContract.parmReportCaption(reportname);

//str getreportname = dataContract.parmReportCaption();///  This line of code gets passed parameter, i checked
//throw error(strFmt("parmReportName() is %1", getreportname));  ///  This line of code gets passed parameter, i checked
controller.startOperation();
}

Maybe there is more simple way to pass report name in DP class?

Best regards,

Roberts

Using the data contract is the only way - that’s the input for the RDP class. But I would pass the report name - I would use a value with business meaning (such as an enum with the type of a report, which may be shared by multiple designs).

What you should do when you get an error is run your code in debugger and checking where things go wrong. Neverheless I do see something suspicious in your code even without debugging. You’re assuming that SrsReportDataProviderBase.parmDataContract() returns SrsReportDataContract, but it should be returning your data contract class instead. Debug your code to see if your assumption isn’t really wrong.

Hi Martin,

My data contract class is SrsReportDataContract (defined in controller). Maybe you cant apply parmDataContract() to SrsReportDataContract as you would in case you would have created your own unique controller class? Maybe there is another method to apply for SrsReportDataContract? When I try to check available methods of contract class I receive in DP after calling it with parmDataContract() it doesnt show parmDataContract().

Best regards,

Roberts

Please follow my advice and debug your code. You’ll see that you’re wrong.

I suspect that you don’t know how to define a data contract. It’s not done in the controller at all - it should be defined in SRSReportParameterAttribute attribute in your RDP class. For example:

[SRSReportParameterAttribute(classStr(MyContract))]

You claim that your contract is SrsReportDataContract (which is a different thing) suggests that you don’t have any contract class yet, therefore you’ll need to create it and add a variable and parm* method for the value you want to pass to your data provider. Don’t forget DataContract and DataMember attributes.

In the controller, you’ll be able to get your contract by calling this.parmReportContract().parmRdpContract().

Hi Martin,

I created new Controller class:

[DataContractAttribute]
public class EBRetailLabelContract
{
    str reportSelection;

    [DataMemberAttribute('ReportSelection')]
    public str parmReportSelection(str _reportSelection = reportSelection)
    {
        //throw error(strFmt("ReportSelection() is %1", reportSelection));
        reportSelection = _reportSelection;
        //throw error(strFmt("ReportSelection() is %1", reportSelection));
        return reportSelection;
    }

}

In DP Class I defined:

    EBRetailLabelContract contract = this.parmDataContract() as EBRetailLabelContract;
    str test = contract.parmReportSelection();
    throw error(strFmt("test is %1", test));

As well as defined:

[
SRSReportParameterAttribute(classStr(EBRetailLabelContract))
]

And added lines in controller class main method:

		EBRetailLabelContract contract;
 
        contract = controller.getDataContractObject() as EBRetailLabelContract;
        contract.parmReportSelection(controller.parmReportName());

        controller.startOperation();

At the moment there is no null reference error as before. However, its I still cant get value of the parameter passed in my DP class, the str test doesnt get any value. StrFrmt test value is empty.

The value however is passed to contract class and it can be received in controller class.

Can you please help?

Best regards,

Roberts

It seems to me that you’re skipping a step You should get a dialog with a field for “ReportSelection”. Do you see it? And do you have the expected value there?

Note that your value may be overwritten with a value loaded from usage data, because you’re setting it at a wrong place. Do it either prePromptModifyContract() OR preRunModifyContract(). I would likely use the latter.

Can you explain me a little bit, maybe there is the problem. It seems that in my controller class at the moment I have defined 2 contract methods. One is based on SrsReportDataContract and one on my new contract class. Am I correct?

    public static void Main(Args _args)
    {
        RetailLabelControllerEBSkyBaltia_Ext controller = new RetailLabelControllerEBSkyBaltia_Ext();
        SrsReportDataContract dataContract;
        SRSPrintDestinationSettings printSettings;

        controller.parmArgs(_args);
        //throw error(strFmt("controller.parmArgs(_args);"));
        dataContract = controller.parmReportContract();
        if (dataContract)
        {
            printSettings = dataContract.parmPrintSettings();
            if (printSettings)
            {
                // Download the report in pdf format.
                printSettings.printMediumType(SRSPrintMediumType::File);
                printSettings.fileFormat(SRSReportFileFormat::PDF);
                printSettings.fileName(controller.parmReportName() + '.pdf');
            }
        }

        //throw error(strFmt("parmReportName() is %1", controller.parmReportName()));
		EBRetailLabelContract contract;
        //EBRetailLabelContract contract = contract as EBRetailLabelContract;
        contract = controller.getDataContractObject() as EBRetailLabelContract;
        contract.parmReportSelection(controller.parmReportName());



        str reportname = contract.parmReportSelection();
        
        //dataContract.parmReportSelection(reportname);

        //str getreportname = dataContract.parmReportCaption();
        //throw error(strFmt("parmReportSelection() is %1", reportname));
        controller.startOperation();
    }

in controller class method prePromptModifyContract() I have reference to this.parmReportContract() which seems to be SrsReportDataContract type based on methods.

    protected void prePromptModifyContract()
    {
        super();
        this.parmShowDialog(false);
        this.setRanges(this.parmReportContract().parmQueryContracts().lookup(this.getFirstQueryContractKey()));
        

Do I need to add my new controller definition here? Im a little bit confused.

The controller class is based on original RetailLabelController class. I just need to add a way how to pass report name values to my DP class.

Baest regards,

Roberts

You’re confusing different types of contracts. What you get from this.parmReportContract() in a controller isn’t an RDP contract. You won’t receive this object in your RDP class.

You should focus in your RDP contract, i.e. EBRetailLabelContract.

Thanks Martin, now I undertand that there can be 2 contract classes, one standard and one RDP. I added these line to my prePromptModifyContract() method:

    protected void prePromptModifyContract()
    {
        super();
        this.parmShowDialog(true);
        this.setRanges(this.parmReportContract().parmQueryContracts().lookup(this.getFirstQueryContractKey()));
        
		EBRetailLabelContract contract;
        //EBRetailLabelContract contract = contract as EBRetailLabelContract;
        contract = this.getDataContractObject() as EBRetailLabelContract;
        contract.parmReportSelection(this.parmReportName());
    }

I put the dialog window param to true and now I see my report name values:

However, in my DP class I still receive no values:

        EBRetailLabelContract contract = this.parmDataContract() as EBRetailLabelContract;
 
        str test = contract.parmReportSelection();
        throw error(strFmt("test is %1", test));
        switch(contract.parmReportSelection())

test value is empty.

Best regards,

Roberts

I tried getting hashcodes of contract in DP class with contract.GetHashCode() and in controller class with the same method. The values are different. Could it be somehow connected to my problem of not receiving values in DP class?

Best regards,

Roberts

I refreshed the report datasource and by doing it sucessfully added my new report parameter. That worked.

Thanks for support!

Best regards,

Roberts