Uploading available document of a product while creating a purchase order

Hello,

I am using ax2012.

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,

    ttsBegin;
    inventTable = InventTable::find(purchLine.ItemId);
    ecoResProduct = EcoResProduct::findByDisplayProductNumber(purchLine.ItemId);

    while select forUpdate docuRef
        where docuRef.RefTableId == ecoResProduct.TableId &&
        docuRef.RefRecId == inventTable.Product
    {
        docuActionArchive = new DocuActionArchive();
        docuActionArchive.add(docuRef, docuRef.Name);
    }
    ttsCommit;

Can anyone help me with the code how to check all the BOM lines for the product and also to avoid duplicates uploading duplicate documents.

Thanks

Wekey

  1. You need to find the active BOM version for that item - \Data Dictionary\Tables\InventTable\Methods\bomId
  2. See this method, \Data Dictionary\Tables\WHSShipmentTable\Methods\createShipmentNotes

Hello Kranthi,

Thanks for you reply.

I can able to relate how to avoid duplicate documents but regarding BOM its bit confusing as I could able to relate it with my code can u able to provide any code for me?

And also I am getting this error when i try to attach the document with the above code I mentioned earlier in my post,

Quality4.PNG

Thanks

Try using \Classes\Docu\copy
What confusion do you have regarding to BOM?

Before that I couldnt able to attach my document.

See the following code for your reference,

 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   = new DocuActionArchive();
            docuActionArchive.add(docuRef,docuValueProduct.Name +"."+ docuValueProduct.FileType);
            info('attached');
        }

Tel me where I am wrong.

Thanks

What issue do you have with this code? Have you tried Docu::copy()?
This could be a issue,
docuRefProduct.RefTableId == (tableNum(ecoResProduct) || tableNum(inventTable)) &&
docuRefProduct.RefRecId == inventTable.Product &&

Docu::copy? No I didnt try that yet

Can you help me with the code for finding active, valid and approved BOM version and its lines, I don know how to iterate through the BOM lines

You can find the BOMId using \Data Dictionary\Tables\InventTable\Methods\bomId
By using that BOMId loop through the Table/BOM

I used the following code to get the bomID but how to iterate through all the bom’s cos it is fetching only one,

static void Test_ListActiveBOMVersion(Args _args)
{
    InventTable inventTable;
    BOMVersion  bomVersion;
    InventDim   inventDim;
    InventSite  inventSite;
    ;
    select firstonly SiteId from inventSite;
    inventDim.InventSiteId = inventSite.SiteId;
    inventDim = InventDim::findOrCreate(inventDim);
    info("Item Number, Active Formula/BOM");
    while select *
        from inventTable
        where inventTable.PmfProductType == PmfProductType::BOM
    {
        bomVersion = 
            BOMVersion::findActive(inventTable.ItemId, DateNull(), 0, inventDim);
        if (bomVersion)
        {
            info(strFmt("%1, %2", inventTable.ItemId, bomVersion.BOMId));
        }
    }
}

While select from BOM
where BOM.BOmId == bomVersion.BOMId
{
// do
}

I also want iterate through the Lines of BOM lines how to achieve that?

You mean if the BOM line is also a BOM, then you want to expand it?

Yes Exactly.

For Instance if you see,

The above seen is an Item and the item has the following BOM,

There are three Lines and there are further lines for each of them for example if you see the item CSS_CSF in the BOM lines have the following lines,

They have further more lines and they have their own respective lines. I need to iterate through all of them until there is no item .

Hope you understand .

You should be doing something like below (calling the same method inside it).
Check if there circularity on BOM. If there is circularity, it may go into infinite loop.
Write a class and have a method like below,
In this example BOMFind is the class.
Note - the below code is only for your reference.
static void BOMFindMethod(BOMId _bomId)
{
BOM bom;
InventTable inventTable;
BOMId bomId;

while select bom
where bom.BOMId == _bomId
{
info(strFmt(’%1 → %2’, bom.BOMId, bom.ItemId));
inventTable = InventTable::find(bom.ItemId);

if (inventTable.isBOMAllowed())
{
bomId = inventTable.bomId(systemDateGet(), bom.BOMQty, bom.inventDim());
if (bomId)
{
BOMFind::BOMFindMethod(bomId);
}
}
}
}