It is important that the user of the BOM Window is made aware of the impact of the changes before they are applied and transferred to ERP. 

In addition to updating the properties or updating the states it can be useful to add and/or remove entities in the BOM Window. By adding new entities to the BOM Window it is possible to display to the user that for example a row is going to be deleted because it is currently part of the BOM in ERP but no longer present in the Vault BOM.


These entities can be added to the powerGate BOM Window using the Add-BomWindowEntity Cmdlet. They can also be removed using the Remove-BomWindowEntity Cmdlet.


In the following example the BOM for a "Balcony Railing" is used. It consists of two outer rails, multiple smaller rails in the middle and a thick railing on top all made of different materials:


Adding BOM Rows to the BOM Window

In order to add BOM rows to the powerGate BOM Window you can use Add-BomWindowEntity with -Type BomRow. It is also required to pass the -Parent argument in order to specify for which BOM the BOM row should be added.


For our example we customized the the "Check-Boms" function to add BOM rows that no longer exists in the Vault BOM but are still part of the ERP BOM:

foreach($vaultBom in $boms) {
    $erpBom = Get-ERPObject -EntitySet "Boms" -Keys @{ "ParentNumber"= $vaultBom.Bom_Number } -Expand "Children"
    foreach($erpBomRow in $erpBom.Children) {
        $vaultBomRow = $vaultBom.Children | Where-Object { $_.Bom_Number -eq $erpBomRow.ChildNumber -and $_.Bom_PositionNumber -eq $erpBomRow.Position }
        if($null -eq $vaultBomRow) {
            $properties = @{
                'Number'=$erpBomRow.ItemName
                'Bom_Number'=$erpBomRow.ChildNumber
                'Bom_Quantity'= $erpBomRow.Quantity
                'Bom_PositionNumber'=$erpBomRow.Position
            }
            $erpBomRow_to_remove = Add-BomWindowEntity -Type BomRow -Parent $vaultBom -Properties $properties
            $erpBomRow_to_remove | Update-BomWindowEntity -Status 'Remove' -ToolTip "Position will be deleted in ERP" -Properties $erpBomRow_to_remove 
        }
    }
}


Let's assume an engineer decided that the Balcony rail does not require the vertical thick rails and removes them from the assembly as well as the Vault BOM. Since the BOM has not been transferred yet they are still part of the BOM in ERP. Therefore a new BOM row gets added to the BomWindow with Status "Remove" to let the user know that the row is going to be removed from the ERP BOM after a "Transfer".


Additional BOM and Material information is provided for the newly added BOM row by passing the Entity property:  'Number' and the BOM properties: 'Bom_Number', 'Bom_Quantity',' Bom_PositionNumber' to the Add-BomWindowEntity cmdlet.

Interesting here is that by passing the 'Number' entity property, the BOM row has even additional information 

from the Item (The property 'Material'). This is because the Item "Thick Rail.ipt" already exists and by passing this Name again for the newly added BOM row as an entity property, the row is linked to the same Item.


When to use BOM properties and when to use entity properties for new BOM Rows?

In general, most properties for a newly created BOM row contain BOM information from BomServices and should therefore be created as BOM properties. For each occurrence of a BOM row the BOM information can be different.


In certain cases, however, it can be useful to make use of entity properties. For example when Item Information from MaterialServices is required to be shown for all BOM row occurrences that are linked to the same item.


Removing BOM Rows from the BOM Window

In order to remove BOM row from the powerGate BOM Window you can the use Remove-BomWindowEntity cmdlet. The row that needs to be removed has to be passed as -InputObject parameter.


For our example we customized the the "Transfer-Boms" function to remove BOM rows from the BOM Window that were previously marked with the Status 'Remove' in the "Check" operation:

function Transfer-Boms($boms) {
foreach($bom in $boms) {
foreach ($bomRow in $bom.Children) {
if ($bomRow._Status -eq "Remove") {
Remove-BomWindowEntity -InputObject $bomRow
}
}
}
}
Note: BOMs that have children can not be removed.

See Also

powerGate BOM Window (coolOrange wiki)

Show-BomWindow (coolOrange wiki)

BomRow object (coolOrange wiki)

Add-BomWindowEntity (coolOrange wiki)

Remove-BomWindowEntity (coolOrange wiki) 

Update-BomWindowEntity (coolOrange wiki)