Tuesday 20 January 2015

Get control and control value in Dynamics AX form

With Dynamics AX 2012, accessing form's controls and their values is not very difficult, like in previous versions. You can access control object in code behind either dynamically as well as statically.

If you have a StringEdit control on your form with name "StringEdit_ShiftCode", you can access it through code in the following way: -


//define name for the control 
#define.ctrlShiftCode('StringEdit_ShiftCode')
//declare and define control.
FormStringControl shiftCode = this.form().design().control(#ctrlShiftCode);
Now you can get every property and methods for this control, like, shiftCode.text().

This is good if you have a dynamics form and controls. But if you have a static form then you can get the form's controls directly by names. For example, if you have a StringEdit control with name "StringEdit_ShiftCode" then change this control's AutoDeclaration property to 'Yes'. Now you can access this control's properties directly by specifying its name.Here is its example: -
str shiftCodeValue = StringEdit_ShiftCode.text();
 
 
 

No comments:

Post a Comment