Data Entity add computed field

 We have this product import module that has a lot of entities, the main identifier or product number is store in one table. The references to that product is through a GUID. In one of the entitties I need to add a computed field for export. The fastest way to do this is to add a computed string value. One could think that adding some postLoad logic would do the trick, but this field will then not be exported through Data management, only visible in OData.


I've added these two fields:



EPDNr is not a computed field but populated in the postLoad method with this syntax:


public void postLoad() {     EPDProduktDto produktDto;     

    super(); select firstonly EPDNr      from produktDto         where produktDto.ProduktGUID == this.ProduktGUID;

    

    this.EPDNr = produktDto.EPDNr;

}


EPDNrComputedField is as you might have guessed a computed field.


Populated on the server with the method below, please do notice that the values are not in quotations, looks like server adds these when returning the value. 


public static server str computedFieldEPDNr()

{     str EPDNr;

EPDNr = strFmt(@'SELECT EPDNR ' +                     'FROM EPDPRODUKTDTO ' +                     'WHERE PRODUKTGUID = CONVERT(uniqueidentifier,%1)' + //because GUID is categorized as a unique identifier                     'AND DATAAREAID = %2' //do notice that there are no quotation symbols '' og "" ,SysComputedColumn::returnField(tableStr(EPDBasispakningDtoEntity), identifierStr(EPDBasispakningDto), fieldStr(EPDProduktDto, ProduktGUID )) ,SysComputedColumn::returnField(tableStr(EPDBasispakningDtoEntity), identifierStr(EPDBasispakningDto), fieldStr(EPDProduktDto, DataAreaId )));          return EPDNr; }



Only the computed field is visible in the SQL server:


SELECT EPDNRComputedField, *

    FROM EPDBasisPakningDtoEntity

    WHERE ProduktGUID = CONVERT(uniqueidentifier, 'FCF49C6B-1F7F-418B-8FD9-861A45F680A1')





Whilst in OData both columns are visible:


To export value in Data Management you need to :

  1. Add the field to the Staging table. 

  2. Check that the field is in your target mapping for the entity. If you do not see your field do the following:
    1. Regenerate target mapping
    2. Truncate the entity list 
    3. Refreshed entity list

  3. If you now run a DataManagement project you get only the computed field and not the post loaded one














Comments

Popular posts from this blog

Call a simple Logic app from X++

SysOperationFramework with use of Query

Retail Attributes on sales lines