web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

get Parameter from Contract class to DP class

(0) ShareShare
ReportReport
Posted on by 380

Evening,

I`ve been struggling with a problem. I need to launch a SSRS report from a form. For this reason I`m using a Controller class, a Data Contract class and a Data Provider Class. Controller class simply gets Args from caller and sets parameters in Data Contract class. That works fine. The tricky part is that I cant get the parameter from Data Contract to Data provider class. Inside the Data Provider class I have an object of the Data Contract, but when I try to get the parameter, it returns me an empty value.

I present you the code snippets, so that the view could be clearer.

Controller class:

class SalesPackageListController extends SrsReportRunController
{
}

public static client void main(Args args)
{
    SalesPackageListController controller = new SalesPackageListController();

    controller.parmReportName(ssrsReportStr(PackageListReport, PackageListLT));
    controller.parmArgs(args);
    controller.startOperation();
}

protected void prePromptModifyContract()
{
    CustPackingSlipJour                         CustPackingSlipJour;
    SalesPackageListDataContract                contract;
    ;

    CustPackingSlipJour = this.parmArgs().record();
    contract = this.parmReportContract().parmRdpContract() as SalesPackageListDataContract;
    contract.parmSalesId(CustPackingSlipJour.SalesId);
}


Data Contract class:

[DataContractAttribute]
public class SalesPackageListDataContract
{
    SalesId                 SalesId;
}

[DataMemberAttribute("SalesId")]
public SalesId parmSalesId(SalesId _salesId = SalesId)
{
    ;

    SalesId = _salesId;
    return SalesId;
}


Data Provider class:

[SRSReportParameterAttribute(classstr(SalesPackageListDataContract))]
public class SalesPackageListDP extends SRSReportDataProviderBase
{
    SalesPackageListHeaderFooterTmp                     SalesPackageListHeaderFooterTmp;
    SalesPackageListDetailsTmp                          SalesPackageListDetailsTmp;
}

public void processReport()
{
    SalesPackageListDataContract     SalesPackageListDataContract;
    CustPackingSlipTrans             CustPackingSlipTrans;
    SalesId                          salesId;
    ;
    
    SalesPackageListDataContract = this.parmDataContract();
    salesId = SalesPackageListDataContract.parmSalesId();    
        
    while select * from CustPackingSlipTrans
    where CustPackingSlipTrans.SalesId == salesId
    {
        SalesPackageListDetailsTmp.clear();
        SalesPackageListDetailsTmp.SalesId = CustPackingSlipTrans.SalesId;
        SalesPackageListDetailsTmp.ItemId = CustPackingSlipTrans.ItemId;
        SalesPackageListDetailsTmp.insert();
    }        
}


So, I cant get the salesId variable in Data Provider`s method processReport. Any suggestions what could be wrong?


*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    Have you verified that the value is set correctly in prePromptModifyContract()? And is it still there after prompt (= closing the dialog)?

  • RajeshLanka Profile Picture
    380 on at

    Yes, the value is set correctly on contract.parmSalesId(CustPackingSlipJour.SalesId);

    About the second question part: I don`t really get it. There is no prompt. It`s a report for a selected record. But after overriding preRunModifyContract method, the value is still set correctly.

    P.S. The object of Data Contract class in Data Provider class does not throw any errors.

  • Suggested answer
    Mohammad Raziq Ali Profile Picture
    2,486 on at

    Hi rajesh,

    What about your getTempTable() method?

    have you used that method, if yes ,then don't forget to specify

    [SRSReportDataSetAttribute(tablestr('TempTable'))] before method signature.

    Please let us know

  • RajeshLanka Profile Picture
    380 on at

    Hello,

    yes, I have used that method to store data to tmpTables, but the problem does not lie in there. If I hardcode some value and insert that value to a tmpTable, then the value is inserted in the tmpTable. For that reason (because it works fine) I did not mention those methods. But now I will.

    Data Provider class:

    [SRSReportDataSetAttribute(tablestr('SalesPackageListDetailsTmp'))]
    public SalesPackageListDetailsTmp getSalesPackageListDetails()
    {
        ;
    
        select * from SalesPackageListDetailsTmp;
        return SalesPackageListDetailsTmp;
    }
    
    [SRSReportDataSetAttribute(tablestr('SalesPackageListHeaderFooterTmp'))]
    public SalesPackageListHeaderFooterTmp getSalesPackageListHeaderFooterTmp()
    {
        ;
    
        select * from SalesPackageListHeaderFooterTmp;
        return SalesPackageListHeaderFooterTmp;
    }

  • Verified answer
    Mohammad Raziq Ali Profile Picture
    2,486 on at

    Hi rajesh,

    Just check with this following code.

    You just modified your code with this updated code

    salesPackageListDataContract = this.parmDataContract() as SalesPackageListDataContract ;

    Please let us know.

    If this post helps you, Please verify this answer.

  • RajeshLanka Profile Picture
    380 on at

    The suggestion worked. Thank you.

    Might I ask, what does the "as SalesPackageListDataContract" part exactly do and why it isn`t enough to just get dataContract object from parmDataContract() method?

  • Mohammad Raziq Ali Profile Picture
    2,486 on at

    Hi Rajesh,

    As far as my limited knowledge is concern, It runs on SysOperationalFramework where you specifies the reference to parmDataContract() method which resides in Base Class. So, It takes your contract class as parameter and send this reference to Service class which you avoided.

    Anyway, Happy DaXing

    If this helps you, please verify the solution.  

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    To be honest, I'm surprised by this behavior and the last reply didn't really explain any of it.

    The "as" operator merely casts a variable to another type and either keeps the object intact (if the type is compatible) or it returns null. You shouldn't get some other non-null object.

    For example, you call parmDataContract(), which returns a SalesPackageListDataContract instance. But the return type of parmDataContract() is Object, because it might return anything. That the Object is SalesPackageListDataContract is just one specific case.

    If you add "as SalesPackageListDataContract", the return type of the expression changes to SalesPackageListDataContract. Note that we're talking only about types, the object itself is (or should be) kept exactly the same in all cases.

    X++ is very benevolent regarding types and it happily allows you to do something like this:

    Object o = getSomeObject();
    SalesPackageListDataContract dc = o;

    On the second line, I'm assigning "an object" to a variable of SalesPackageListDataContract. It's wrong if o doesn't contain an object of a type compatible with SalesPackageListDataContract. That's why such assignment is rejected by compilers of many other languages. For example, you would get a compilation error in C#.

    For research purpose, could you please compare the content of salesPackageListDataContract variable when you call salesPackageListDataContract = this.parmDataContract() and when salesPackageListDataContract = this.parmDataContract() as salesPackageListDataContract? Thank you.

  • Community Member Profile Picture
    on at

    Hello,

    I have the same problem too, and I am curious knowing why is the problem and how solving it (add "as SalesPackageListDataContract" as Mohd Raziq Ali suggested didn't much help, and I presume RajeshLanka did another thing, as I do - full CIL compile, restart AOS, etc).

    Everything is declared properly, and I have many reports that works fine.

    I shall mentioned that the datacontract class - I had some other problems, and I mistakenly delete+add it again (maybe this made the problem, because ax "remembers" the old class somehow.

    Also did full compile, but still have the problem.

    Thanks :)

  • Mohammad Raziq Ali Profile Picture
    2,486 on at

    Hi Eitan,

    Could you please share your code with us, as we are also curious to know what thing prevents your reports to run as expected.

    Thanks,

    Raziq

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans