17 October 2019

BOM Explode X++ logic in AX 2012 D365 FO

class BOMExplode
{
    date                        _date = mkDate(22,09,2019);
    void itemExplode(ItemId _ItemId, int _level = 0, BOMQty _bomQty = 1)
    {
        BOM                         bomTable;
        BOMVersion                  bomVersion;
        boolean                     enable;
        InventTestVariableId        cvQualityGroupId;
        Level                       level = _level;
       
        while select bomVersion
            where bomVersion.ItemId == _itemid
                && bomVersion.Active
                && bomVersion.FromDate <= _date//DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone())
                && (!bomVersion.ToDate || bomVersion.ToDate >= _date)//DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone()))
        {
            if (bomVersion.RecId)
            {
                While select bomTable
                    where bomTable.BOMId == bomVersion.BOMId
                {
                    Info(strFmt("Parent Item: %1 Part Number: %2 Quantity: %3, Level: %4 ",bomVersion.ItemId,bomTable.ItemId, bomTable.bomQty,level));
                    if (this.hasChild(bomTable.ItemId))
                    {
                        this.itemExplode(bomTable.ItemId, level + 1, bomTable.BOMQty);
                    }
                }
            }
        }
    }

    boolean hasChild(ItemId _itemId)
    {
        BOMVersion  bomVersion;
        boolean     ret = false;

        select firstonly bomVersion
            where bomVersion.ItemId == _itemid
                && bomVersion.Active
                && bomVersion.FromDate <= _date//DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone())
        && (!bomVersion.ToDate || bomVersion.ToDate >= _date);//DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone()));

        if (bomVersion.RecId)
        {
            ret = true ;
        }

        return ret;
    }

    public static void Main(Args args)
    {
        BOMExplode bomExplode = new BOMExplode();

        bomExplode.itemExplode("A20HBA06B7");

    }

}

1 comment:

  1. Water Hack Burns 2lb of Fat OVERNIGHT

    More than 160 000 men and women are losing weight with a simple and secret "water hack" to drop 2 lbs each night while they sleep.

    It's simple and works on everybody.

    This is how you can do it yourself:

    1) Go grab a glass and fill it half full

    2) Proceed to learn this awesome hack

    so you'll be 2 lbs skinnier as soon as tomorrow!

    ReplyDelete

Give me the commetns and solutions

Ledger Voucher creation Framework and x++ code to create ledger voucher

 Please click her for MS reference file Below is the out of the box example reference and code. SalesInvoiceJournalPostSubBill_Extension-...