Search This Blog

Saturday, September 3, 2022

Import data using data entity from x++ in dynamics 365 F&O

This is quite common requirement we receive that we need to import the data using data entity with the x++. 

so to Import the data using data entity, we need to make sure that Definition group should be created and we will going to use it in the code. 

I have tested with the CustCustomerGroupEntity data entity and it was working fine. 

Runnable class to import the customer related data 

internal final class TestReadFileWithDataEntity

{

    /// <summary>

    /// Class entry point. The system will call this method when a designated menu

    /// is selected or when execution starts and this class is set as the startup class.

    /// </summary>

    /// <param name = "_args">The specified arguments.</param>

    public static void main(Args _args)

    {

        DMFDefinitionGroup  definitionGroup = DMFDefinitionGroup::find("Import customer group");//Sepcify definition group name

        DMFExecutionId      executionId     = DMFUtil::setupNewExecution(definitionGroup.DefinitionGroupName);

        FileUploadTemporaryStorageResult        storageResult = File::GetFileFromUser() as FileUploadTemporaryStorageResult;

        SharedServiceUnitFileID fileId;

 

        if (storageResult && storageResult.getUploadStatus())

        {

            fileId = storageResult.getFileId();

            DataFileImportExportUtils_W::importDataFromFileToAX(fileId,definitionGroup.DefinitionGroupName,"CustCustomerGroupEntity",true);

        }

 

    }

 

}


We can check the history as well. Navigate to the data definition group that we have created. As per below 












Click on the Job history and we can see the recently some new customer group has been updated.












We can see the staging data as per below 



No comments:

Post a Comment