Tuesday, October 18, 2022

Copy attachments from one form to another in D365FO

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

Here we are copying attachment from custom table  to CustTable.

pubic Satic void main(Args _args)
{

    DocuRef    docuRefFrom;
    //Current record    
    CustomTable   current = _args.record();
    CustTable   custTable = CustTable::find('Cust-00001');

    While select docuRefFrom
                  where docuRefFrom.RefRecId   ==  current.RecId
                     && docuRefFrom.RefTableId ==  current.TableId
                    && docuRefFrom.RefCompanyId == current.DataAreaId
              {
                      //Copy attachment into CustTable
                      DocuRef::createFromDocuRef(docuRefFrom, custTable.RecId , tableNum(CustTable));
                                                                        OR
                      DocuRef::createFromDocuRef(docuRefFrom, custTable.RecId , custTable.TableId);
               }

}