Translate

Thursday, June 14, 2012

Segmented Entry Control on Forms in Dynamics AX 2012 [Ledger Dimension/Ledger account lookup X++]

Friends,
I was going through the segmented entry control on the form and found that AX 2012 has changed the way ledger dimensions populate on the form.
A new control type has been added in AX 2012 as shown below.
You can add a segmented entry control to a form when you want that form to show an account number and related dimensions from the chart of accounts. In addition, you use the segmented entry control to associate an account and related financial dimensions with the record that appears in the form. To update the values in the control, you can use a lookup or a list of recently used values to select a value for each segment. Finally, you can have the control validate the updated segments to ensure the account and financial dimensions are a valid combination[msdn]
For more information : click here
Let me show you how to quickly get this working on the form.
To explain this, I am using ProjParameters Table.
Add a new Int64 field to ProjParameters Table by name “LedgerDimension”
and set the extendedDataType as “LedgerDimensionAccount”
Add a new relation with “DimensionAttributeValueCombination” table.Right click on the relations Node >> New relation and set the relations as shown below
Now create a normal relation as shown below. Right click on the newly created relations and chose Normal relation.

we are done with the table customization and lets move to the form “ProjParameters”
Go to AOT >> Forms >> ProjParameters >> right click on the form and restore.
Expand the datasources node >> projParameters >> Drag and drop the LedgerDimension field on to Design >> General TabPage as shown below.
Once you drag drop this datafield ledgerDimension, a new segmentedEntry control will be created. Save the form and open the form [Ctrl + O].
you will find the ledger account control in the General Tab. But when you try to look at the ledger accounts, you will not find anything[empty - no lookup values]..

hmm.. interesting..what am I missing here?? Let me help you how to get this..
In AX 2012, there is a class “LedgerDimensionAccountController” which does the trick of population of accounts. LedgerDimensionAccountController class provides control interaction logic for any use of the account number control in the UI.
Lets proceed. Go to the classdeclaration and create an object for LedgerDimensionAccountController class as shown below
public class FormRun extends ObjectRun
{
//..standard code
LedgerDimensionAccountController ledgerDimensionAccountController;
}
Override the init() method of the form and instantiate the object of the class as shown below with the projparameters_ds and the field name “LedgerDimension”
public void init()
{
//…standard code
// Initialize account controllers
ledgerDimensionAccountController = LedgerDimensionAccountController::construct(projParameters_DS, fieldstr(ProjParameters, LedgerDimension));
}
Go to datasources >> projParameters >> fields >> ledgerDimension >> add a new method called resolvereference as shown below
public Common resolveReference(FormReferenceControl _formReferenceControl)
{
return ledgerDimensionAccountController.resolveReference();
}

After you add the control to the form, you must provide the control with the ability to retrieve data, select a value for a segment, and validate the selected values. Typically, you use a controller class to override several segmented entry control methods.
Now, expand Design node >> segmented Entry control which has been recently created >> right click and override the “jumpref” method and add the below code
public void jumpRef()
{
ledgerDimensionAccountController.jumpRef();
super();
}
Right click again on th segmented entry control and override “loadAutoCompleteData” method and add the below code
Public void loadAutoCompleteData(loadAutoCompleteDataEventArgs _e)
{
super(_e);
ledgerDimensionAccountController.loadAutoCompleteData(_e);
}
Right click again on the segmented control and override “loadsegments” method and add the below code
public void loadSegments()
{
super();
ledgerDimensionAccountController.parmControl(this);
ledgerDimensionAccountController.loadSegments();
}
Right click on the segmented entry control and override “segmentValueChanged” and add the below code
public void segmentValueChanged(SegmentValueChangedEventArgs _e)
{
super(_e);
ledgerDimensionAccountController.segmentValueChanged(_e);
}
Lastly , right click on the segmented control and override “validate” method and add the code below
public boolean validate()
{
boolean isValid;
isValid = super();
isValid = ledgerDimensionAccountController.validate() && isValid;
return isValid;
}
For more details on the overridden methods above : click here
Done, we are good now to see the ledger accounts with the segments [if any] in the lookup.
Right click on the projParameters form and open the form.
Happy DAXing.. :)

6 comments:

  1. Hi, this is good example. I have tried and this. For getting the dimensions we will be using the DimensionDefaultEDT and viewing in the forms. Could you explain in which case we should directly create field in the table and use this segmeneted control.

    ReplyDelete
    Replies
    1. Buddy u can use this functionality over a form where u want MainAccount & Dimensions to be input by the user. As this functionality is tightly linked with Accounting Structures, so as per setups in GL, dimensions would be visible\hidden on form no need to change the code.

      Delete
  2. Hi,
    In the form LedgerJournalTransVendPaym, I need to display the name of the vendor corresponding to the account selected in the SegmentedEntry:LedgerJournalTrans_AccountNum. The client wants to see the account AND the name in a separate column.
    Can you help?

    ReplyDelete
    Replies
    1. I solved my problem. I used the AccountName method.

      Delete
  3. Hey ,

    Need little help

    I am doing the same process as mentioned but whenever i select the ledger account on the form and move to the next field .. AX Instance Stops working

    Can anyone help in this regard ..??

    Thanks in advance

    ReplyDelete
  4. Hey ,

    Need little help

    I am doing the same process as mentioned but whenever i select the ledger account on the form and move to the next field .. AX Instance Stops working

    Can anyone help in this regard ..??

    Thanks in advance

    ReplyDelete