web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Uploading available document of a product while creating a purchase order in ax 7

(0) ShareShare
ReportReport
Posted on by 302

Hello,

I am using ax7.

When an item (Released Product) is entered on a PO line, and the line is saved , system need to upload the document handling at the line level. All “External” documents contained on the PRODUCT related to the Released Product should be uploaded.

I also want to check BOM versions for the item and all items underneath it according to its valid, approved and active BOM (go down all levels of the BOM tree). If the above condition failed system should not upload and throw an error. Please check the below image for further reference.

Quality1.png

Quality2.png

I also want to Remove duplicates based on the document Description.

To achieve this first I tried the following code in insert method of the PurchLineType class to upload the document regardless of the BOM, but I am getting the following error.

Quality.PNG

This is the code I have written,

using System.Reflection;
public static class PurchLineType_insert_EventHandlerTES
{
    /// <summary>
    /// Uplaods related Doucument of te product
    /// </summary>
    /// <param name="args"></param>
    [PostHandlerFor(classStr(PurchLineType), methodStr(PurchLineType, insert))]
    public static void PurchLineType_Post_insert(XppPrePostArgs args)
    {
        PurchLineType       purchLineType       = args.getThis();
        PurchLine           purchLine           = purchLineType.getPurchLine();
        DocuActionArchive   docuActionArchive   = new DocuActionArchive();
        InventTable         inventTable         = InventTable::find(purchLine.ItemId);
        EcoResProduct       ecoResProduct       = EcoResProduct::findByDisplayProductNumber(purchLine.ItemId);
        DocuRef             docuRef;      

        ttsbegin;
        while select forupdate docuRef
            where docuRef.RefTableId    == ecoResProduct.TableId &&
                  docuRef.RefRecId      == inventTable.Product                  
        {
            docuActionArchive.add(docuRef,docuRef.Name);
        }
        ttscommit;
    }

}


Please help me where I am wrong and also suggest me the code for adding BOM Lines to my existing code.

Thanks

*This post is locked for comments

I have the same question (0)
  • Wekey Profile Picture
    302 on at

    Hello!

    Any updates for the issue?

  • Wekey Profile Picture
    302 on at

    Hello Everyone!,

    I have changed my code into this. But I couldnt able to achieve my requirement . ANy Ideas on this?

    Thanks

  • Wekey Profile Picture
    302 on at

    Hello everyone,

    I changed my coding. But still I coudlnt able to achieve my requirement. AnyIdeas on where I am wrong?

    using System.Reflection;
    public static class PurchLineType_insert_EventHandlerTES
    {
        /// <summary>
        /// Uplaods related Doucument of te product
        /// </summary>
        /// <param name="args"></param>
        [PostHandlerFor(classStr(PurchLineType), methodStr(PurchLineType, insert))]
        public static void PurchLineType_Post_insert(XppPrePostArgs args)
        {
            PurchLineType       purchLineType       = args.getThis();
            PurchLine           purchLine           = purchLineType.getPurchLine();
            PurchTable          purchTable          = purchLine.purchTable();
            DocuActionArchive   docuActionArchive   = new DocuActionArchive();        
            InventTable         inventTable         = InventTable::find(purchLine.ItemId);
            EcoResProduct       ecoResProduct       = EcoResProduct::findByDisplayProductNumber(purchLine.ItemId);
            DocuRef             docuRef;
            DocuRef             docuRefProduct;
            DocuValue           docuValueProduct;    
                    
            while select docuRefProduct
                where docuRefProduct.RefTableId     == (tableNum(ecoResProduct) || tableNum(inventTable)) &&
                      docuRefProduct.RefRecId       == inventTable.Product   &&
                      docuRefProduct.Restriction    == DocuRestriction::External
                join  docuValueProduct
                where docuValueProduct.RecId        == docuRefProduct.ValueRecId
            {
                docuRef.TypeId          = docuRefProduct.TypeId;
                docuRef.Name            = docuRefProduct.Name;
                docuRef.Restriction     = docuRefProduct.Restriction;
                docuRef.RefTableId      = tableNum(PurchTable);
                docuRef.RefRecId        = purchTable.RecId;
                docuRef.RefCompanyId    = curExt();
                docuRef.insert();
    
                docuActionArchive.add(docuRef,docuValueProduct.Name +"."+ docuValueProduct.FileType);
            }
            
        }
    
    }


Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 24

#2
Michel ROY Profile Picture

Michel ROY 14

#3
imran ul haq Profile Picture

imran ul haq 8

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans