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.
Only in case of connection problems with ERP cmdlets the status of the according BOMs and rows is automatically set to Error.

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

Checking whether Vault file BOMs exist in the ERP system: BOMs are marked as “New”, “Identical” and with “Error” icons:

function Check-Boms($boms) {
   foreach($vaultBom in $boms) {
      if($vaultBom._CategoryName -eq 'Base') {
         $vaultBom | Update-BomWindowEntity -Status 'Error' -StatusDetails "BOMs for files of the category group 'Base' should not be processed"
      }

      $erpBom = Get-ERPObject -EntitySet 'Boms' -Keys @{ 'ParentNumber'= $vaultBom.Bom_Number }

      if($? -and -not $erpBom) { 
         Update-BomWindowEntity -InputObject $vaultBom -Status New -StatusDetails 'BOM does not exist in ERP'
      }
      if($erpBom) {
         Update-BomWindowEntity -InputObject $vaultBom -Status Identical -StatusDetails 'BOM exists in ERP'
      }
   }
}

Note: In case of connection problems during the Get-ERPObject cmdlet, the status of the currently iterated $vaultBom object is automatically set to ‘Error’.
Further exception details can be retrieved via automatic variables like $? and $Error[0].

Checking whether the Vault file BomRows are “Identical” to those of the ERP BOMs, whether 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
      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 -eq $null) {
            $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
         }
         elseif($vaultBomRow.Bom_Quantity -cne $erpBomRow.Quantity) {
            Update-BomWindowEntity -InputObject $vaultBomRow -Status Different -StatusDetails "'Quantity' is different:`nVault '$($vaultBomRow.Bom_Quantity)'`nERP '$($erpBomRow.Quantity)'"
         }
         else {
            Update-BomWindowEntity -InputObject $vaultBomRow -Status Identical
         }
      }
      #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
            }
         }
      }
   }
}