
Previously, I talked about how to disable and re-enable a BOM row, but that’s only half the story. There are actually 2 types of “off” BOM rows. The type I discussed earlier is an Item that has been disabled. The other type is a Component BOM Row, which means that the child is not a real Item. Components have the potential to be an Item, but are not quite there yet.
Reading the Unassigned Component rows
When calling GetItemBOMByItemIdAndDate, make sure your the BOMViewEditOptions includes ReturnUnassignedComponents. If not, then the Component rows will be omitted. When you get back the ItemBOM, the BOMCompArray is where you can find the Component objects. The BOM rows themselves are represented by objects the ItemAssocArray. This array contains both Item-to-Item and Item-to-Component links. So you need to account for both cases when reading ItemAssoc objects.
In the case of an Item-Component link, the BOMCompId will have a valid value but CldItemID and CldItemMasterID will be 0. The parent will always be an Item, so ParItemID and ParItemMasterID will have a valid value in all cases. There is no such thing as a Component-to-Component link in an Item BOM.
Turing on the component BOM row
If you have a Component row that you want to enable, there are several steps. You have to promote the Component into an Item. Then you need to update the BOM association so that it points to the Item instead of the Component.
I’d better just post some sample code for this one. Here is a function to enable a single component BOM row.
|
// C# publicvoid EnableComponentBOMRow(Item parentItem, string componentName) { ItemService itemSvc = connection.WebServiceManager.ItemService;
// put the parent item in edit mode Item editableItem = itemSvc.EditItems( newlong [] {parentItem.RevId}).First();
// read the BOM data ItemBOM bom = itemSvc.GetItemBOMByItemIdAndDate( editableItem.Id, DateTime.MinValue, BOMTyp.Tip, BOMViewEditOptions.Defaults | BOMViewEditOptions.ReturnExcluded | BOMViewEditOptions.ReturnUnassignedComponents);
// locate the component we want to enable BOMComp component = bom.BOMCompArray.FirstOrDefault(n => n.Name == componentName);
// promote the component itemSvc.AddComponentsToPromote(newlong [] {component.Id}, ItemAssignAll.Default, false); DateTime timestamp; GetPromoteOrderResults orderResult = itemSvc.GetPromoteComponentOrder(out timestamp); itemSvc.PromoteComponents(timestamp, orderResult.PrimaryArray); ItemsAndFiles promoteResult = itemSvc.GetPromoteComponentsResults(timestamp);
// update the BOM link to point to the Item // instead of the Component ItemAssoc bomLink = bom.ItemAssocArray.First(n => n.ParItemID == editableItem.Id && n.BOMCompId == component.Id); itemSvc.UpdateItemBOMAssociations( editableItem.Id, newlong [] {bomLink.Id}, newlong [] {promoteResult.ItemRevArray[0].Id}, newdouble [] {bomLink.Quant}, newbool [] {bomLink.IsStatic}, newbool [] {true}, newint [] {bomLink.BOMOrder}, newstring [] {bomLink.PositionNum}, newBOMEditAction [] {BOMEditAction.Update}, BOMViewEditOptions.ReturnBOMFragmentsOnEdits);
// commit changes to the the parent item and // the newly promoted item List<Item> itemsToCommit = newList<Item>(); itemsToCommit.Add(editableItem); itemsToCommit.AddRange(promoteResult.ItemRevArray); itemSvc.UpdateAndCommitItems(itemsToCommit.ToArray()); } |
|
' VB.NET PublicSub EnableComponentBOMRow(parentItem AsItem, componentName AsString) Dim itemSvc AsItemService = connection.WebServiceManager.ItemService
' put the parent item in edit mode Dim editableItem AsItem = itemSvc.EditItems(NewLong() {parentItem.RevId}).First()
' read the BOM data Dim bom AsItemBOM = itemSvc.GetItemBOMByItemIdAndDate(editableItem.Id, DateTime.MinValue, BOMTyp.Tip, BOMViewEditOptions.Defaults OrBOMViewEditOptions.ReturnExcluded OrBOMViewEditOptions.ReturnUnassignedComponents)
' locate the component we want to enable Dim component AsBOMComp = bom.BOMCompArray.FirstOrDefault(Function(n) n.Name = componentName)
' promote the component itemSvc.AddComponentsToPromote(NewLong() {component.Id}, ItemAssignAll.[Default], False) Dim timestamp AsDateTime Dim orderResult As GetPromoteOrderResults = itemSvc.GetPromoteComponentOrder(timestamp) itemSvc.PromoteComponents(timestamp, orderResult.PrimaryArray) Dim promoteResult AsItemsAndFiles = itemSvc.GetPromoteComponentsResults(timestamp)
' update the BOM link to point to the Item instead of the Component Dim bomLink AsItemAssoc = bom.ItemAssocArray.First(Function(n) n.ParItemID = editableItem.Id AndAlso n.BOMCompId = component.Id) itemSvc.UpdateItemBOMAssociations(editableItem.Id, NewLong() {bomLink.Id}, NewLong() {promoteResult.ItemRevArray(0).Id}, NewDouble() {bomLink.Quant}, NewBoolean() {bomLink.IsStatic}, NewBoolean() {True}, _ NewInteger() {bomLink.BOMOrder}, NewString() {bomLink.PositionNum}, New BOMEditAction() {BOMEditAction.Update}, BOMViewEditOptions.ReturnBOMFragmentsOnEdits)
' commit changes to the the parent item and the newly promoted item Dim itemsToCommit AsNewList(OfItem)() itemsToCommit.Add(editableItem) itemsToCommit.AddRange(promoteResult.ItemRevArray) itemSvc.UpdateAndCommitItems(itemsToCommit.ToArray()) EndSub |
Turing on the Component BOM row
Technically it’s not a Component row any more. It’s a normal row since the child is an Item. If you want to turn off the row, you can disable it. Disabling the row leaves the Item intact. So the row is still an Item-to-Item link.
If we want to truly revert the state, so that it’s an Item-to-Component link, you can delete the Item. This will cause the BOM to revert the row back to using the Component. This process only works for Items that come from Components. If the Item was created directly in the Item Master, then there is no Component. Deleting an Item in this case will simply remove it from all BOMs that it’s in.
Where do Components come from
Components come from CAD files. When a CAD file is uploaded to Vault, the CAD plug-in includes BOM information. That information becomes Components, and Components become Items. If you want more information, you can read the article about the BOM Pipeline. The basic takeaway is that Components are hooked to CAD files. Items created directly in the Item Master have no Components.

Leave a Reply