How to update entity properties in the BOM Window

Entity properties are displayed in the BOM and the Items tab. They generally contain information that is relevant for the item. 

By default the Name property is always available in the BOM Tab and in the Item Tab.

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

In contrast to BOM properties the entity properties must be defined without the "Bom_"  prefix in the powershell script.

In this example the item with the Name "Case Back.ipt" is used in both the "Pad Lock.iam" and the "Catch Assembly.iam":

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 entity property

In addition to the default properties we can also add additional custom entity properties to our Items e.g. the property ArticleNumber

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 entity property
'ArticleNumber' = 87
}
New-Object PSObject -Property @{
'_Name' = 'Catch Assembly.iam'
'Bom_Number' = 'Catch Assembly'
'Bom_PositionNumber' = 1
'Bom_Quantity' = 1

# custom entity property
'ArticleNumber' = 88
}
)
}
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"

# custom entity property
'ArticleNumber' = 86
}
Show-BomWindow $file
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 property ArticleNumber it has to be selected in the Field Chooser.

Note: Even though "Case Back.ipt" is used 2 times in the BOM tab, the entity property ArticleNumber stays the same for both.

Fill the BOM Window with ERP values

To show the values from the ERP system in the BOM Window the property ArticleNumber can be updated with the values from the ERP system.

This can be done in the Check-Items function. In this case we retrieve the value of ArticleNumber from the ERP and update the affected Item. 

function Check-Items($items) {
foreach($item in $items) {
$ERPItem = Get-ERPObject -EntitySet 'Items' -Keys @{'ID' = $item._Name}
$item | Update-BomWindowEntity -Status Different -Properties @{
'ArticleNumber' = $ERPItem.ArticleNumber
}
}
}
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 Item Tab.

The value in the column ArticleNumber will be updated with the value coming from your ERP system.

As you may notice the ArticleNumber is updated in the in the Item Tab and the Bom Tab.

Transfer the values back to ERP

During the Transfer operation we can now update the ArticleNumber and Description of the items in the ERP system.

In order to do so, we should add the Transfer-Items function where we can access the previously updated value for the ArticleNumber:

function Transfer-Items($items) {
foreach($item in $items) {
Update-ERPObject -EntitySet 'Items' -Keys @{'ID' = $item._Name} -Properties @{'ArticleNumber' = $item.ArticleNumber; 'Description' = "Updated!"}
}
}
Again the BOM Window has to be closed in order to re-execute your powershell script!

After clicking the Transfer Button in the Item Tab the ERP properties ArticleNumber and Description will be updated on the items in the ERP system.

See Also