Tuesday, 20 August 2013

How to add a single address for an entity X++ - Address Book Framework AX 2012

Hi Everyone,

Today I want to delve into a little X++ and discuss the Address Framework in AX 2012.

The Address Framework helps to integrate a customized entities address with the Logistics and Location and gives your customized development the standard look and feel of AX 2012.

Step 1. Create  a Doctor Table with some fields likes the ones in the below table. We are focusing on the Location Field. The Location Field has the LogisticsLocationRecId as the EDT and is an Int64 type. Create a foreign key relation with this field and the LogisticsLocation Table Recid.

Step 2. Now we have to add two data sources to the Doctor Form.

Add the Doctor Table and the Logistics Postal Address Form. On the LogisticsPostalAddress Data source set the Join Source  property (ITL_DoctorTable) and Link Type property to OuterJoin.


Step 3. Now we have to create the Menu Items that go along with the address, such as New, Edit, Clear, Map. For reference look at the following display Menu Items 
  1. LogisticsPostalAddressNewBankgroup
  2. LogisticsPostalAddressEditBankgroup
  3. LogisticsPostalAddressClearBankgroup
  4. LogisticsPostalAddressMap
Simply study these Menu Items once you have under stood them duplicate them and add them to the action pane in your form.

Set the menu buttons Auto Declaration Property to Yes.

Set the Data Source Property of the Action Pane to Logistics Postal Address.

Step 4. Then add a String Edit field to the form field. Set the name and label properties as per your liking. Set the data source field to LogisticsPostalAddress table and the data field property to Address.

Step 5. Add this to the Class Declaration of the form.

 Public Class FromRun Extends ObjectRun  
 {  
    LogisticsPostalAddressFromHandler   AddressController;  
 }  

Step 6. Add a form Method  that will return the address controller.

 public LogisticsPostalAddressFormHandler getAddressController()   
 {     
    return addressController;   
 }  

Step 7. Add the following code to the Form's Init Method.

 public void init()   
 {     
    addressController = LogisticsPostalAddressFormHandler::newParameters(DoctorTable_Ds, LogisticsPostalAddress_DS);  
    addressController.callerUpdateQuery(fieldNum(DoctorTable, Location);  
 }   

Step 8. Override the active method of the DoctorTable Data Source

 public int active()   
 {     
    int ret;     
    ret = super();     
    if (ret)     
    {       
       addressController.callerActive();                 
       addressController.callerUpdateButtons(newAddress, editAddress, clearAddress,mapButton);    
    }     
    return ret;   
 }   

Step 9. Add LogisticsPostalAddressTable as a datasource and override the validateWrite and write methods.
 public boolean validateWrite()   
 {     
    return true;   
 }   
 public void write()   
 {   
   //super();   
 }   

Stay Tuned for more Posts dealing with the more complicated Scenarios of the Address Book Framework in AX 2012

No comments:

Post a Comment