Sunday, 3 March 2019

Adding Product attachment document using X++


Description:
Adding attachment against the product in x++

Setup file path
Step 1. Go to Organization and administration
Step 2. Go to setup
Step 3. Document management node
Step 4. Open Document type menu
Step 5. Select file option in the for grid
Step 6. Select attachment directory like “c:\TEMP\folder name”

X++ Code:
// this method will be created bom attachment and bom description
public static void documentAttachmentForBom(Args _args)
{
    // declaration
    DocuRef                    docuRef;
    DocuActionArchive     docuArchive;
    DocuType                  docuType;
    Filename                   fileNameWithPath;
    BOMTable                 bomTable = BOMTable::find(“000003”);


//getting current file directory location
    select docuType
        where docuType.Name == 'File'
            && docuType.FilePlace == DocuFilePlace::Archive;

    if(docuType.RecId)
    {
        fileNameWithPath = docuType.ArchivePath + fileName;
        info(fileNameWithPath);
    }

    //field mapping
    ttsbegin;
    docuRef.clear();
    docuRef.TypeId = 'File';
    docuRef.Name = fileNameWithPath;
    docuRef.Notes = “Attachment description”;
    docuRef.Restriction = DocuRestriction::External;
    docuRef.RefTableId = tableNum(BomTable);
    docuRef.RefRecId = bomTable.RecId;
    docuRef.RefCompanyId = curext();
    docuRef.insert();

    //Code to attach file
    docuArchive = new DocuActionArchive();
    docuArchive.add(docuRef, fileNameWithPath);
    ttscommit;
 }

Select file:

Bom attachment screen:


No comments:

Post a Comment

Step-by-Step Guide to Restore a SQL BACPAC File - Microsoft dynamics D365 Fin & Ops

 Restore steps for bacpac file in to SQL server - Microsoft dynamics D365 Fin & Ops. Log in to LCS and navigate to the asset library. On...