Announcements
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();
}
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.
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).
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()?
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.
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?
André Arnaud de Cal...
294,017
Super User 2025 Season 1
Martin Dráb
232,852
Most Valuable Professional
nmaenpaa
101,158
Moderator