Get-BomRows

This function is called recursively for loading the BOM tree.
The returned BomRows are the children of the BOMs shown in the BOM Window.

Get-BomRows [-BomHeader] <Item>

TypeNameDescriptioninput/outputMandatoryDefault value
BomRow / ItemBomHeaderThe parent of the BomRows to returninputYes

PsObject[] ← typically an array of powerVault FileBomRows or ItemBomRows or empty.
It is recommended for every BomRow to provide at least the following properties:

  • _Name ← serves as the unique identifier for every BOM and Item
  • Bom_Number
  • Bom_PositionNumber
  • Bom_Quantity

The first time the function will be invoked with the root entity passed to Show-BomWindow. This could be a powerVault File or Item.
Later the function will be invoked again recursively for each BomRow returned earlier.

In general two categories of properties can be provided for all the BomRows:

  • BOM properties are properties prefixed with 'Bom_' (e.g. Bom_PositionNumber, Bom_Unit, …).
    They are displayed only in the BOM-Tab without the prefix.
  • Entity properties are all other properties (e.g. Description, _Category, …).
    They are available in both the BOM-Tab and the Items-Tab.

Since every BomRow is a PsObject, custom BOM properties and Entity properties can be attached and later displayed as columns in the BOM Window.

In order to signal a leaf of the BOM tree (a BomRow that has no more children) the function should return an empty array.

When an exception is thrown within this function, the passed $bomHeader element is marked as failed in the BOM Window.

Note: The function will only be called once for BOMs that are located multiple times in the BOM tree.

Return a single Bom row with custom properties:

function Get-BomRows($BomHeader){
    if($BomHeader._Name -eq 'BomRow'){
        return @()
    }
    $BomRow = New-Object -TypeName PsObject -Property @{
        #Recommended properties
        _Name='BomRow'
        Bom_Quantity=10
        Bom_PositionNumber=1
        Bom_Number='BomRow'
        _Category='Part' #Additional entity property
        Bom_Unit='Each' #Additional BOM property
    } 
    return @($BomRow)
}
Return all BomRows of a Vault item:
function Get-BomRows($bomHeader) {
   $bomRows = Get-VaultItemBom -Number $bomHeader._Number
   $bomRows | foreach {
      if($bomHeader.Bom_RowOrder) {
         Add-Member -InputObject $_ -Name Bom_RowOrder -Value ("{0}.{1}" -f $bomHeader.Bom_RowOrder,$_.Bom_RowOrder) -MemberType NoteProperty -Force
      }
   }
   return $bomRows
}

Return all children of a Vault item or file, by handling 'Purchased' and 'Virtual' components:

function Get-BomRows($bomHeader) {
   if($bomHeader._EntityType.Id -eq "FILE") {
      if($bomHeader.Bom_Structure -eq 'Purchased') {
         $bomRows = @()
      }else{
         $bomRows = Get-VaultFileBom -File $bomHeader._FullPath
      }
   }elseif($bomHeader._EntityType.Id -eq "ITEM"){
      $bomRows = Get-VaultItemBom -Number $bomHeader._Number
   }else{
      $bomRows = @()
   }
   $bomRows | foreach {
      if($_._EntityType.Id -eq $null) {
         Add-Member -InputObject $_ -Name "BomType" -Value "Virtual" -MemberType NoteProperty -Force
      }
      if($bomHeader.Bom_RowOrder) {
         Add-Member -InputObject $_ -Name Bom_RowOrder -Value ("{0}.{1}" -f $bomHeader.Bom_RowOrder,$_.Bom_RowOrder) -MemberType NoteProperty -Force
      }
   }
   return $bomRows
}