Data Entity with computed and virtual fields AX7 (Dynamics 365 for Operations)

Hi,

Here i gonna create new data Entity for Sales Line with computed and virtual fields in AX7 (Dynamics 365 for Operations).

Add New Data Entity to Project



In the Data entity wizard, specify the properties for the data entity that we are creating. Use the values that are shown in the following screen shot.


Click Next

Click Convert labels to field names to generate names from the existing labels and Select below
checked field name as below.




Click Finish. Data entity item and staging table are added to the project.


Synchronize and Build the Project by right click Project.

Adding Mapped Fields in Data Entity

Right Click on Data Entity and Add new Mapped Field (Item Id and CustAccount)



Map the field in Properties like below

Note: Provide Mandatory YES and Allow Edit NO for Primary key Fields which creates primary in SQL Server Table




Add new Computed Field.

 Computed fields are used mostly for reads.


Rename Field and give display method as below



Add New method for above field

Add new code as below and for mapping ItemName Computed Field

public class TestSOLineDataEntity extends common
{
    /// <summary>
    ///
    /// </summary>
    private static server str  displayItemName()
    {
        DataEntityName      dataEntityName= tablestr(TestSOLineDataEntity);
       TestSOLineDataEntity sTestSOLineDataEntity;

        SalesLine salesLine;
        select * from salesLine where salesLine.SalesId == sTestSOLineDataEntity.SalesOrder && salesLine.ItemId ==sTestSOLineDataEntity.ItemId;
        return salesLine.itemName();
     }
}


Add new Virtual Field for Customer Name.
  • Is controlled by custom X++ code.
  • Read and write happens through custom X++ code.


Set the Is Computed Field property to No.


To Assign value this field Go to Mehtods --> Override -->postLoad()


Add below code

public class TestSOLineDataEntity extends common
{
   
 /// <summary>
    ///
    /// </summary>
    public void postLoad()
    {
        super();
        this.CustName=CustTable::find(this.CustAccount).name();
    }

}


New Data entity is ready with mapped, computed and Virtual Fields.




Reference

https://ax.help.dynamics.com/en/wiki/data-entities/
https://ax.help.dynamics.com/en/wiki/data-entity-computed-columns-and-virtual-fields/

Comments