web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Getting Error while importing Attachments through custom Data entity in d365 fo

(5) ShareShare
ReportReport
Posted on by 296

Hi All,

I have developed a custom Data Entity by taking reference from the standard entity CustomerAttachmentsV2Entity, which allows importing attachments. In this entity, there is a field called DocumentId, which is the primary key and of type GUID.

1.When I import a single attachment without providing DocumentId in Excel, it works fine.
2.When I try to import multiple records without DocumentId in Excel, the import throws an error.
3.I attempted to generate the GUID through code by writing logic in the staging table insert method and also in the onInserting event handler, but these methods were not triggered.
4.I need guidance on how to generate a new GUID for every record during import. Since I have to import nearly 10,000 attachments, manually entering GUIDs is not feasible.

the below is the error 

<?xml version="1.0"?><Errors><Error><ErrorCode>-1071636471</ErrorCode><SubComponent>OLE DB Destination [76]</SubComponent><Description>SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80004005.
An OLE DB record is available.  Source: "Microsoft SQL Server Native Client 11.0"  Hresult: 0x80004005  Description: "The statement has been terminated.".
An OLE DB record is available.  Source: "Microsoft SQL Server Native Client 11.0"  Hresult: 0x80004005  Description: "Violation of PRIMARY KEY constraint 'I_30743STAGINGIDX'. Cannot insert duplicate key in object 'dbo.IIT_RCAPROCESSATTACHMENTSSTAGING'. The duplicate key value is (5637144576, Importing multiple  jpg attachments of RCA, Importing multiple  jpg attachments of RCA-2025-08-28T05:12:38-8E6CE50089534EFB8F6734CB952, 00000000-0000-0000-0000-000000000000).".
</Description></Error><Error><ErrorCode>-1071607767</ErrorCode><SubComponent>OLE DB Destination [76]</SubComponent><Description>SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR.  The "OLE DB Destination.Inputs[OLE DB Destination Input]" failed because error code 0xC020907B occurred, and the error row disposition on "OLE DB Destination.Inputs[OLE DB Destination Input]" specifies failure on error. An error occurred on the specified object of the specified component.  There may be error messages posted before this with more information about the failure.
</Description></Error><Error><ErrorCode>-1073450974</ErrorCode><SubComponent>SSIS.Pipeline</SubComponent><Description>SSIS Error Code DTS_E_PROCESSINPUTFAILED.  The ProcessInput method on component "OLE DB Destination" (76) failed with error code 0xC0209029 while processing input "OLE DB Destination Input" (89). The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running.  There may be error messages posted before this with more information about the failure.
</Description></Error></Errors>
Failed to insert record into staging table. The keys of the record are DEFINITIONGROUP, DOCUMENTID, EXECUTIONID, PARTITION. Duplicate records must be removed from the file prior to import.
'0' 'RCA Process Attachments' record(s) inserted in staging

 

Thanks in advance.

Categories:
I have the same question (0)
  • Sohaib Cheema Profile Picture
    49,438 User Group Leader on at
    Are you sure the issue is with generating a new GUID on insert, and not with the entity itself? Because if it it successfully works without providing the GUID for a single record so why not for two rows, if you try to import two rows
  • Syed Amir Ali Profile Picture
    179 on at
    Hey, 

    You can create a new GUID while inserting the record into your entity. Use the insertEntityDataSource method of the entity.
     
    public boolean insertEntityDataSource(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx)
    {
        switch (_dataSourceCtx.name())
        {
            case dataEntityDataSourceStr(YourEntityNameHere, YourEntityDataSourceNameHere) :
               TableName stagingTable = _dataSourceCtx.getBuffer() as SL_SOBulkUploadStageTable;
                
              if(!stagingTable.DocumentId)
             {
                 stagingTable.DocumentId = newGUID();
             }
     
        }
       
         boolean ret = super(_entityCtx, _dataSourceCtx);
       
         return ret;
    }
     

    If this was helpful, please check the "Does this answer your question?" box and mark it as verified.
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    300,917 Super User 2025 Season 2 on at
    Hi Charan12,

    What is the exact purpose of the GUID field? Note that if this field is part of your primary key, it should be provided in the source file. SQL Server Integration Services is used to get the data from the file directly in the SQL table, before it will trigger any X++ coding. For that reason two records with the same (empty) DocumentID will raise this duplicate key violation.
     
    Suppose you can generate the GUID, then what will ensure uniqueness of the record? In case you will import the same file a second time, it would not recognize the first set of GUIDs and will create duplicate records in F&O instead of updating existing ones. 
     
    So ensure your import will work with a unique key that can be provided in the source file.
  • charan12 Profile Picture
    296 on at
    HI @André Arnaud de Calavon , @Martin Dráb

    1.We don’t want to update the attachments — this is a one-time process where we are importing bulk attachments (around 15,000 records).
    2.When I provide multiple records with unique GUIDs, the entity works fine.
    3.This one-time process involves migrating 15,000 attachments from the legacy system (AX 2009) to D365 FO. that's why we created one custom entity.
    4.We were asked to move the attachments that are stored on the file server (linked with the customer master) through some code in AX 2009.

    As you mentioned, this data entity expects a unique GUID for each record in the Excel file. Generating 10,000+ GUIDs manually is time-consuming, so we prefer automatic GUID generation.

    1.What do you suggest as the best approach to solve this problem?

     

     
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    300,917 Super User 2025 Season 2 on at
    Hi Charan,
     
    Thanks for the clarification and additonal details. As mentioned, you need the GUID in the source file.
    There is an option to generate GUIDs with an Excel formula. You can use the next formula.
    =UPPER(CONCATENATE(
        DEC2HEX(RANDBETWEEN(0,4294967295),8),"-",
        DEC2HEX(RANDBETWEEN(0,65535),4),"-",
        DEC2HEX(RANDBETWEEN(0,65535),4),"-",
        DEC2HEX(RANDBETWEEN(0,65535),4),"-",
        DEC2HEX(RANDBETWEEN(0,4294967295),8),
        DEC2HEX(RANDBETWEEN(0,65535),4)
    ))
    Credits to John MacDougall. You can read more about this trick with some other options on his blog: 5 Ways to Generate a GUID in Microsoft Excel | How To Excel

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 522 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans