How to update BOM properties in the BOM Window

BOM properties are displayed only in the BOM Tab and generally contain information that is relevant only for BOMs and not for items. 

By default the following properties are always available in the BOM Tab:

  • Name
  • Position
  • Quantity
  • Number

In order to provide them with initial data when opening the BOM Window, the BOM properties have to be defined in the Get-BomRows function and populated with data.

In the powerShell script the BOM properties must have the prefix "Bom_" even though they are later displayed without it.

In order to understand the difference between BOM properties and entity properties, we can think about the following situation, in which one item is used multiple times in the same BOM.

The item "Case Back.ipt" is used in both the "Pad Lock.iam" and the "Catch Assembly.iam" but with different quantities:

function Get-BomRows($BomHeader){
if($BomHeader._Name -eq 'Pad Lock.iam'){
return @(
New-Object PSObject -Property @{
'_Name' = 'Case Back.ipt'
'Bom_Number' = 'Case Back'
'Bom_PositionNumber' = 1
'Bom_Quantity' = 3
}
New-Object PSObject -Property @{
'_Name' = 'Catch Assembly.iam'
'Bom_Number' = 'Catch Assembly'
'Bom_PositionNumber' = 1
'Bom_Quantity' = 1
}
)
}
if($BomHeader._Name -eq 'Catch Assembly.iam'){
return @(New-Object PSObject -Property @{
'_Name' = 'Case Back.ipt'
'Bom_Number' = 'Case Back'
'Bom_PositionNumber' = 1
'Bom_Quantity' = 2
})
}
else {
return @()
}
}
 

Now we can start the BOM Window for our PsObject:

$file = New-Object PSObject -Property @{
"_Name" = "Pad Lock.iam"
}
Show-BomWindow $file
 

Define a custom BOM property

In addition to the default BOM properties we can also add additional custom BOM properties to our BomRows e.g. the property Cost.

In order to do so we have to change the Get-BomRows function and provide values for the BomRows:

function Get-BomRows($BomHeader){
if($BomHeader._Name -eq 'Pad Lock.iam'){
return @(New-Object PSObject -Property @{
'_Name' = 'Case Back.ipt'
'Bom_Number' = 'Case Back'
'Bom_PositionNumber' = 1
'Bom_Quantity' = 3

# custom BOM property
'Bom_Cost' = "$(3 * 5000).00 €"
}
New-Object PSObject -Property @{
'_Name' = 'Catch Assembly.iam'
'Bom_Number' = 'Catch Assembly'
'Bom_PositionNumber' = 1
'Bom_Quantity' = 1
}
)
}
if($BomHeader._Name -eq 'Catch Assembly.iam'){
return @(New-Object PSObject -Property @{
'_Name' = 'Case Back.ipt'
'Bom_Number' = 'Case Back'
'Bom_PositionNumber' = 1
'Bom_Quantity' = 2

# custom BOM property
'Bom_Cost' = "$(2 * 5000).00 €"
})
}
else {
return @()
}
}
 

In order to apply the above changes to the Get-BomRows function, we have to close the BOM Window and rerun the script.

To display the Cost property it has to be selected in the Field Chooser. 

Note: BOM properties are marked with an icon: in the Field Chooser:

Fill the BOM Window with ERP values

To show the values from the ERP system in the BOM Window the BomRow properties Bom_Quantity and Bom_Cost can be updated with the values from the ERP system.

This can be done by adding the Check-Boms function.

In this case we retrieve the value of Quantity and BaseCost from the ERP and update the affected BomRow. 

function Check-Boms($boms) {
foreach($bom in $boms) {
$bom | Update-BomWindowEntity -Status Different
foreach ($bomRow in $bom.Children) {
$ERPBomRow = Get-ERPObject -EntitySet 'BomRows' -Keys @{'ParentID' = $bom._Name; 'ChildID'=$bomRow.Bom_Number}
$bomRow | Update-BomWindowEntity -Properties @{
'Bom_Quantity' = $ERPBomRow.Quantity;
'Bom_Cost'="$($ERPBomRow.Quantity * $ERPBomRow.BaseCost).00 €"
}
}
}
}
Please note that the BOM Window should be closed again in order to re-run the script!

Now you can click on the Check Button in the BOM Window.

The values in the columns Quantity and Cost will be updated with the values coming from your ERP system.

Transfer the values back to ERP

During the Transfer operation we can now update the Quantity and TotalCost of the rows in the ERP system.

In order to do so, we should add the Transfer-Boms function where we can access the previously calculated values for Bom_Quantity and Bom_Cost:

function Transfer-Boms($boms) {
foreach($bom in $boms) {
foreach ($bomRow in $bom.Children) {
Update-ERPObject -EntitySet 'BomRows' -Keys @{'ParentID' = $bom._Name; 'ChildID'=$bomRow.Bom_Number} -Properties @{
"Quantity" = $bomRow.Bom_Quantity;
"TotalCost" = $bomRow.Bom_Cost
}
}
}
}
Again the BOM Window has to be closed in order to re-execute your powershell script!

After clicking the Transfer Button in the BOM Window the ERP properties Quantity and TotalCost will be updated on the rows in the ERP system.

See Also