D365FO – AX – Copy attachments from Project quotations (SalesQuotationTable) to new or existsing Project (ProjTable) while using “Transfer to project” functionality

We want to copy attachments from Project quotation table to new or existsing project from “Transfer to project” functionality

Create an extension of SalesQuotationProjLinkWizard class

[ExtensionOf(classStr(SalesQuotationProjLinkWizard))]

Create a final class

final class Al0SalesQuotationProjLinkWizard_Extension

{

…………..

}

Create “al0CopyAttachmentsQuotationToProject” custom method.

This method retreieve attachments from SalesQuotationTable to ProjTable.

private void al0CopyAttachmentsQuotationToProject(RecId _SalesQuotationRecId, RecId _ProjTableId)
{
    DocuRef salesQuotationDocuRef;
    //Search if exists an attachment for SalesQuotationTable
    while select  salesQuotationDocuRef
                where salesQuotationDocuRef.RefTableId == tableNum(SalesQuotationTable)
        &&   salesQuotationDocuRef.RefRecId == _SalesQuotationRecId
    {
        //Copy attachment into Project
        DocuRef::createFromDocuRef(salesQuotationDocuRef,_ProjTableId , tableNum(ProjTable));
    };
}

Inside class create a Chain of Command of “linkQuotationToProjectMethod” and call “al0CopyAttachmentsQuotationToProject” method. This will copy attachments to project

public void linkQuotationToProject(ProjId _projId, ProjInvoiceProjId _projInvoiceProjId)
{
    ProjTable           projTableLocal  = ProjTable::find(_projId);
    next linkQuotationToProject(_projId, _projInvoiceProjId);
    //Copy salesQuotationTable attachments to existsing ProjTable
    this.al0CopyAttachmentsQuotationToProject(salesQuotationTable.RecId,projTable.RecId);

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 )

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