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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to create BOM version, Bom line through code in ax 2012?

(0) ShareShare
ReportReport
Posted on by 865

Hi all,

 

I want to create BOM version and BOM line through code and approve and activate it also, but through Job.

I Tried with direct insertion in table but it is showing some garbage value.

can any one please help me on this..

  

*This post is locked for comments

I have the same question (0)
  • Zedben Profile Picture
    15 on at

    Even though this was asked quite a while ago, I had the same question.  Unable to find the answer, I researched and found out how to do it myself.  

    In order to do what you are requesting, you have to first create an entry in the BOMTable and one or more entries in the BOM table.  I had to pull these out of my class, so they are sloppy and a lot is missing (validation within the class to name one thing).  

    An example of setting the BOMTable:

    private boolean setBOMTable()
    {
        boolean ret=true;
        InventTable = InventTable::find("<The Relevant Item Number>", false);    
    
    //some validation here
        if (ret)
        {
            if (!BOMTable)
                BOMTable.initFromInventTable(inventTable);
            BOMTable.BOMId = "<The BOM ID - perhaps a number sequence>";
            BOMTable.Name = "<The name of the BOM>";
            if (BOMTable.validateWrite())
            {
                BOMTable.write();
                return true;
            }
        }
    
    //error handling here
    
    return false;
    }
    

    An example of setting the BOM Line

    private boolean setBOM()
    {
        InventTable invent = InventTable::find("<the item on the bom line>", false);
        boolean ret = true;
        
    //validation here
        
        if (ret)
        {
            if (!BOM)
                BOM.initValue();
        
            BOM.BOMType = BOMType::Item;
            BOM.BOMConsump = BOMConsumpType::Variable;
            BOM.ItemId = invent.ItemId;
            BOM.BOMQty = 1.00; //the amount on the line
            BOM.Calculation = NoYes::Yes;
            BOM.BOMId = BOMTable.BOMId;
            BOM.OprNum = 0;
            BOM.UnitId = "EA"; //or any other UOM the item can handle
            BOM.InventDimId = InventDim::findOrCreateBlank(); //for products, not masters
            BOM.ScrapConst = 0.00; //amount of scrap
        
            if (BOM.validateWrite())
            {
                BOM.write();
                return true;
            }
        }
        //error handling here
        return false;
    }

    Version:

    private boolean setBOMVersion()
    {   
        InventTable InventTable = InventTable::find("Item to attach BOM to");
        BOMVersion.initValue();     
        //some validation goes around here
        
        BOMVersion.InventDimId = BlankDim;
        BOMVersion.initFromInventTable(InventTable);
        BOMVersion.initFromBOMTable(BOMTable);
        try
        {
            if (BOMVersion.validateWrite())
            {
                this.tableRecord(BOMVersion);
                return true;
            }                    
        }
        catch
        {
            Global::exceptionTextFallThrough();
        }    
        
        this.logError(strFmt("(%1) version failed write validation.", this.getExcelStringValue(InventTable.ItemId)));
        
        return false;
    }
    

    Activation:

    private boolean setBOMActive()
    {
        BOMApprove bomApprove = new BOMApprove();    
        RecId approver = HcmWorker::findByPersonnelNumber("A personnel number").RecId;
        boolean ret=true;
        
        try
        {
            bomApprove.init();
            bomApprove.parmApprover(approver);
            bomApprove.parmBOMId("The BOMID to approve");
            bomApprove.run();
            BOMVersion.selectForUpdate();
            BOMVersion.Approved = true;
            BOMVersion.Active = true;
            BOMVersion.Approver = approver;
            ttsBegin;
            BOMVersion.write();
            ttsCommit;
        }
        catch
        {
            this.logError(strFmt("(%1) approval failed.", this.getExcelStringValue(#ItemCode)));
            ret=false;
        }
        
        return ret;
    }
    
    
    
    Hopefully this helps anyone else with this question.  

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans