Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

error contract = this.parmdataContract()

(0) ShareShare
ReportReport
Posted on by 5

Hi,

I am new to Dynamics AX and I am unable to understand few things in coding as I started learning AX. I am not from a coding background please guide me here or could you please refer me a book or channel where I can get in depth knowledge on these codes.

These are few lines of codes from Contract, DP ,UIbuilder and Controller classes, where I am unable understand how they work in current code and purpose of calling these methods and Classes

  1.DP_CustVendContract contract = this.parmDataContract() as DP_CustVendContract;

2. contract = this.dataContractObject()

     contract = this.parmdataContract()

   

3.SysTableLookup sysTableLookup;


sysTableLookup = SysTableLookup::newParameters(tableNum(HL_HospitalTable), santoshlookup);

4.public static void main(Args _args)
{

 ItemTransactionSummaryController controller;

    controller = new ItemTransactionSummaryController();

}


 

  • Martin Dráb Profile Picture
    232,852 Most Valuable Professional on at
    RE: error contract = this.parmdataContract()

    No, you can't use the object in contract if you don't assing anything to the variable. It'll contain null instead of an object and any attempt to use methods of this null reference will end up with a runtime exception. Why don't you simply try running your second code snippet? You'll see the behavior for yourself.

    The purpose of getting a contract object is getting the existing contract object, so you can work with it, e.g. reading values that users selected in the dialog. If you just declare a variable, you can't expect values magically appear there.

  • Satish.G Profile Picture
    5 on at
    RE: error contract = this.parmdataContract()

    Hi,Martin.

    As you said I can access variables, methods or any object from a class using that class instance.In my case "contract" is the instance of DP_VendCustContract class right so using contract variable I can access all the objects from DP_VendCustContract right(please correct me if I am wrong).Even without this line of code(DP_VendCustContract  contract = this.parmDataContract() as DP_VendCustContract;)

    t

     Public void processreport(
     {
     dp_vendcustcontract contract = this.parmdatacontrol() as dp_vendcustcontract
     accountnum = contract.parmaccountnum();
     name = contract.parmname();
     }
     
     
     //or i can call the parmmethods from dp_vendcustcontractclass using contract class buffer(contract)
    
    public void processreport(
    {
    
    dp_vendcustcontract  contract
    //using contract buffer i can call the methods from dp_vendcustcontract clas
    contract.parmaccountnum()
    contract.parmname();
    }

    In general scenario not only in my code what is the purpose for getting value from parmDataContract() and casting it into type of DP_VendCustContract even though I can get parmmethod values from DP_VendCustContract class using buffer(contract).

  • Martin Dráb Profile Picture
    232,852 Most Valuable Professional on at
    RE: error contract = this.parmdataContract()

    contract is a vatiable name. I can't tell you what the variable contains in your particular case.

    The current object is the instance of a class where you call the method. For example, you have a class called Car and create a new instance (Car myCar = new Car()). Then you call its method, e.g. myCar.go(), and when you refer to 'this' inside go(), it means the same object that you have in myCar variable.

    If you understand what a variable is and that '=' operator assigns a value of to a variable, what problem do you have with parmDataContract()?

  • Satish.G Profile Picture
    5 on at
    RE: error contract = this.parmdataContract()

    Thank you for your response Martin Dráb.

    it is really helpful and exact explanation what I am looking for.

    I have few doubts in  above explanation please bear with me.

    What do you mean by "current Object".

    contract is the instance of DP_CustVendContract right?

    And I also looked into the source code of parmDataContract() for what value this method( parmDataContract()) is storing and returning value when we call the this method but I am unable to understand code.

    please look into the below snippet.

     public Object parmDataContract(Object _rdpDataContract = rdpDataContract)
        {
            // at runtime this is set in the call to setParameterMap();
            rdpDataContract = _rdpDataContract;
            return rdpDataContract;
        }

    I know about Variable, Methods() and classes 

    Please refer me if there is a way to get the good knowledge on these basic codes.

  • Martin Dráb Profile Picture
    232,852 Most Valuable Professional on at
    RE: error contract = this.parmdataContract()

    this.parmDataContract() calls a method called "parmDataContract" on the current object.

    contract = means that the value (returned from the method) is assigned to the variable called contract.

    as DP_CustVendContract means that the value is cast to DP_CustVendContract type, if it's compatible (it's an instance of DP_CustVendContract class or its children). If it's not the case, null is returned instead.

    If you have no idea what a class, an object, a variable or a method means, you should a learn a bit about programming before continuing, because neither code, documentation or our answers will be understandable to you.

    Please use Insert > Code (in the rich formatting view) to paste source code; it'll be easier to read.

    static void main(Args _args)
    {
        ItemTransactionSummaryController controller;
        controller = new ItemTransactionSummaryController();
    }

    I'll change the category of this question from Other to Development / Customization / SDK. By the way, which version of AX is it about?

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,017 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,852 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans