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.

Syntax

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

Parameters

Type

Name

Description

input/output

Mandatory

Default value

Bom []

Boms

The Boms which should be checked

input

yes

Return type

void

Remarks

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.

Examples

Setting Status and StatusDetails 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 -StatusDetails 'BOM does not exist in ERP'
                } else {
                        Update-BomWindowEntity -InputObject $vaultBom -Status Identical -StatusDetails '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
                                }
                        }
                }
        }
}