powergate:code_reference:commandlets:show-bomwindow:required_functions:check-boms

Check-Boms

This function is executed when clicking the “Check” button within the BOM Tab.
All the BOMs from the BOM Window can be checked against ERP.

Check-Boms [-Boms] <Bom[]>

TypeNameDescriptioninput/outputMandatoryDefault value
Bom[]BomsThe BOMs which should be checked.inputYes

void

Each unique BOM shown in the BOM Window is passed to this function.

It's recommended to update the Status of all the BOMs and their rows with the Update-BomWindowEntity cmdlet.

When an exception is thrown within this function, the BOM Window shows the Exception message of the terminated Check operation.
The Status of all the BOMs and their Children that where not updated, gets automatically changed to Unknown.

Setting Status and tooltip of all the file BOMs that exist in ERP to “Identical” or otherwise to “New”:

function Check-Boms($boms) {
    foreach($vaultBom in $boms) {
        $erpBom = Get-ERPObject -EntitySet "Boms" -Keys @{ "ParentNumber"= $vaultBom.Bom_Number } -Expand "Children"
        
        if($erpBom -eq $null) {
            Update-BomWindowEntity -InputObject $vaultBom -Status New -ToolTip 'BOM does not exist in ERP'
        } else {
            Update-BomWindowEntity -InputObject $vaultBom -Status Identical -ToolTip 'BOM exists in ERP'
        }
    }
}

Checking if the File BomRows are “Identical” as on the ERP-BOMs, if there are “New” once or rows that should be “Removed”

function Check-Boms($boms) {
    foreach($vaultBom in $boms) {
        $erpBom = Get-ERPObject -EntitySet "Boms" -Keys @{ "ParentNumber"= $vaultBom.Bom_Number } -Expand "Children"
       
        #iterating ERP-BOM rows and checking if they exist in the Vault-BOM
        if($erpBom.Children) {
            foreach($erpBomRow in $erpBom.Children) {
                $vaultBomRow = $vaultBom.Children | Where-Object { $_.Bom_Number -eq $erpBomRow.ChildNumber -and $_.Bom_PositionNumber -eq $erpBomRow.Position } | select -First 1
                if( $vaultBomRow -ne $null) {
                    Update-BomWindowEntity -InputObject $vaultBomRow -Status Identical
                } else {
                    $bomRow = Add-BomWindowEntity -Type BomRow -Parent $vaultBom -Properties @{"Bom_Number"=$erpBomRow.ChildNumber;"Bom_PositionNumber"=$erpBomRow.Position; "Bom_Quantity"=$erpBomRow.Quantity;}
                    Update-BomWindowEntity -InputObject $bomRow -Status Remove
                } 
            }
        }
        #iterating Vault-BOM rows and checking if they exist in the ERP-BOM
        if($vaultBom.Children) {
            foreach($vaultBomRow in $vaultBom.Children) {
                $erpBomRow = $erpBom.Children | Where-Object { $_.ChildNumber -eq $vaultBomRow.Bom_Number -and $_.Position -eq $vaultBomRow.Bom_PositionNumber } | select -First 1
                if( $erpBomRow -eq $null) {
                    Update-BomWindowEntity -InputObject $vaultBomRow -Status New
                }
            }
        }
    }
}