Copy attachments between different forms with data – Dynamics 365 for Finance and Operations

Scenario:

Sometime a requirement come that we need to copy the attachment from one form to another with the flow of data.

For example when purchase order creates from sales order then the attachment also need to be flow from sales order to purchase order

Solution:

First thing first -> Identify the relation between new and existing form(tables).

Then use the below code to achieve this.

I used the onInserted event ,you can use the same or whatever suitable for your scenario. Important thing is record should be created in new table then you can copy the attachment.

/// <summary>

    ///

    /// </summary>

    /// <param name=”sender”></param>

    /// <param name=”e”></param>

    [DataEventHandler(tableStr(PurchTable), DataEventType::Inserted)]

    public static void PurchTable_onInserted(Common sender, DataEventArgs e)

    {

        PurchTable purchTable = sender;

        SalesTable salesTable = SalesTable::find(purchTable.InterCompanyOriginalSalesId);

        DocuRef docuRef = DocuRef::findTableIdRecId(salesTable.DataAreaId, salesTable.TableId, salesTable.RecId);

        if (docuRef)

        {

            docuRef.RefTableId = purchTable.TableId;

            docuRef.RefRecId = purchTable.RecId;

            docuRef.insert();

        }

    }

 

//Leave your comments below if you have any query. I will try to help you to solve your problem

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.