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