When a file content is being inbounded from external sources to dynamics, to test this we can create an XML file and add the base64 string to the XML file by converting it in online using File to base64 converters. 

High level resolution steps 

Detailed resolution steps 

Step1: Add a field “File Content” to the entity where the import is happening. 

Step2: Create an Extension class for the entity and add “insertEntityDataSource” method and add the logic to call the code to attach the file. 


[ExtensionOf(dataentityviewstr(WHSInboundLoadHeaderEntity))] 

internal final class SCC_WHSInboundLoadHeaderEntity_Extension 

{ 

    ///  

    /// This method is to attach the file content immediately after record is inserted. 

    ///  

    /// DataEntityRuntimeContext 

    /// DataEntityDataSourceRuntimeContext 

    ///  

    public boolean insertEntityDataSource(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx) 

    { 

        boolean         ret; 

        Filename        fileName; 

 

        ret =  next insertEntityDataSource(_entityCtx,_dataSourceCtx); 

 

        if (_dataSourceCtx.name() == dataEntityDataSourceStr(WHSInboundLoadHeaderEntity, WHSLoadTable) 

            && _entityCtx.getDatabaseOperation() == DataEntitydatabaseOperation::Insert) 

        { 

            WHSLoadTable loadTable = _dataSourceCtx.getBuffer(); 

 

            if (this.SCCFileContents) 

            { 

                fileName = loadTable.LoadId; 

 

                DocuRef::sccAttachFileFromBase64(loadTable, this.SCCFileContents, fileName); 

            } 

        } 

        return ret; 

    } 

 

} 
    

Code Explanation: 

Output:

Add the FileContent to the XML file in the base64 str format. 

Import the XML file for the WHSInboundLoadHeaderEntity. 

Base64 String to XML Dynamics

Navigate to Warehouse Management -> Loads -> All Loads 

Select the Load ID created and open the attachments node.

The file attached through the XML can be found here.

Leave a Reply

Your email address will not be published. Required fields are marked *