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.


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.

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