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

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

a simple draft for copy BOM between company

(0) ShareShare
ReportReport
Posted on by

Hy everybody, below I post a simple job to copy BOM between company (pay attention it's only a draft that could be completed.

... with hope could be useful ...

static void CopyBOMbetweenCmp(Args _args)
{
BOMVersion bomVersion;
BOMTable bomTable;
BOM bom;
InventTable inventTable;

container listBOM = ['ITEM01','ITEM02',...]; //insert list of item to copy

CompanyId destcmp = '111';
CompanyId sourcecmp = '011';
ItemId itemId;
int i;

boolean copyBomversion(bomVersion _bomversion)
{
bomversion bomversionLocal;
//copy bomversion
changecompany(destcmp)
{
bomversionLocal = null;
select firstOnly bomversionLocal where bomversionLocal.BOMId == _bomversion.BOMId;
if(!bomversionLocal.RecId )
{
buf2buf(_bomversion,bomversionLocal);
bomVersionLocal.InventDimId = //todo insert the inventdim of destination company
bomversionLocal.insert();
return true;
}
else
{
info(bomversionlocal.BOMId + " just exists");
return false;
}
}
return false;
}

bomTable copyBomtable(bomTable _bomTable)
{
bomTable bomtableLocal;
//copy bomtable
changecompany(destcmp)
{
bomtableLocal = null;
select firstOnly bomtableLocal where bomtableLocal.BOMId == _bomtable.BOMId;
if(!bomtableLocal.RecId )
{
buf2buf(_bomtable,bomtableLocal);
bomtableLocal.insert();
}
}
return bomtableLocal;
}

bom copyBomLines(bom _bom)
{
bom bomLocal;
//copy bom
changecompany(destcmp)
{
bomLocal = null;
select firstonly bomlocal where bomLocal.bomid == _bom.BOMId
&& bomLocal.ItemId == _bom.ItemId
&& bomLocal.Position == _bom.Position;
if(!bomLocal.RecId)
{
buf2buf(_bom, bomLocal);
if(conFind(listItemNot2Drill, bomlocal.ItemId)>0)
bomLocal.BOMType = BOMType::Item;
bomLocal.InventDimId = //todo insert the inventdim of destination company
bomLocal.insert();
}
}
return bom;
}


void copyBom(inventtable _it)
{
Bom bomSource;
boolean inDepth;
bomSource = //todo insert search of active bom;

if(bomSource.RecId)
{
bomVersion = bomVersion::findActive(bomSource.bomid,systemDateGet(),0,//todo inventdim of reference in bom);
bomTable = bomtable::find(bomSource.BOMId);
inDepth = copyBomversion(bomVersion);
copyBomtable(bomTable);
}

if(!inDepth)
return;

while (bomSource.RecId)
{
switch(bomSource.BOMType)
{
case BOMType::Item : if(inventTable::find(bomSource.ItemId).PmfProductType == PmfProductType::BOM)
{
copyBomlines(bomSource);
copyBom(inventTable::find(bomSource.ItemId));
}
else
copyBomlines(bomSource);
break;
case BOMType::Vendor : copyBomlines(bomSource);
break;
case BOMType::Phantom :
copyBomlines(bomSource);
copyBom(inventTable::find(bomSource.ItemId));
break;
}

next bomSource;
}
};

for(i=1; i<= conLen(listBOM) ; i++)
{
itemId = conPeek(listBOM,i);
select inventtable where inventTable.itemid == itemId;
CopyBom(inventTable);
}


}

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at
    RE: a simple draft for copy BOM between company

    Hi, Daniele:

    Does this code work?

    quatrani

  • Daniele Ferraretto Profile Picture
    on at
    RE: a simple draft for copy BOM between company

    Hi, in my enviroment work fine.

    Bye, Daniele.

  • Community Member Profile Picture
    on at
    RE: a simple draft for copy BOM between company

    Hi, Daniele::

    May I have your final working version? It'd would be very appreciated !!

    quatrani

  • JCHI Profile Picture
    334 on at
    RE: a simple draft for copy BOM between company

    Hi, Daniele:

    May I ask how to get the inventdim of destination company in statement below?

    bomLocal.InventDimId = //todo insert the inventdim of destination company

    Regards

    Quatrani

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#2
Community Member Profile Picture

Community Member 2

#2
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans