In order to create a custom Workflow we first create a new powerJobs Processor job with the name YourCompanyName.TransferVaultFileBom.ps1 in the following directory: %ProgramData%\coolOrange\powerJobs\Jobs.


Within this PowerSell script we can retrieve the Fusion Lifecycle information and additional Workflow Settings that where configured in the Configuration Manager, by using the $tenant and $workflow as described in this article.

For the moment we hardcode all our settings instead, in order to keep our first custom Workflow job as simple as possible.


Connect to Fusion Lifecycle

First you can use the Connect-FLC cmdlet in your custom Workflow job, in order to connect to Fusion Lifecycle with your own credentials:

Import-Module powerFLC
$connected = Connect-FLC -Tenant 'your_tenant_name' -ClientId 'your_client_id' -ClientSecret 'your_client_secret' -UserId 'your_email@example.com'

Create item or update an existing item

After successfully connecting to Fusion Lifecycle you can check if an item already exists in Fusion Lifecycle using the Get-FLCItems cmdlet by searching for specific item Fields. 

In this example the "Part Number" property from a Vault file is used for searching an item that has a field "itemID" with the same value in the 'Items and BOMs' workspace. 

When working with revision-controlled workspaces the "Part Number" in Vault and the "itemID" Field in Fusion Lifecycle must stay the same for all item revisions in Fusion Lifecycle in order to find the according item.

Import-Module powerVault
Open-VaultConnection
$file = Get-VaultFile -Properties @{"File Name"="Pad Lock.iam"}

$workSpace = 'Items and BOMs'
$item = (Get-FLCItems -Workspace $workSpace -Filter ('ITEM_DETAILS:ITEMID="{0}"' -f $file._PartNumber))[0]


The results from the Get-FLCItems cmdlet can be used to validate if no according item exists in Fusion Lifecycle yet.

Therefore a new item can be created in the 'Items and BOMs' workspace using the Add-FLCItem cmdlet:

if (-not $item) {
$item = Add-FLCItem -Workspace $workSpace -Properties @{
"itemID" = $file._PartNumber;
"Description" = $file._Description;
"Unit of Measure" = "Each"
}
}


For the case when an item already exists in Fusion Lifecycle for the according Vault file, its Field values can be updated with the current Vault properties using the Update-FLCItem cmdlet:

else {
$item = Update-FLCItem -Workspace $item.Workspace -ItemId $item.Id -Properties @{
"Description" = "$($file._Description), Updated"
}
}


Upload the Vault file thumbnail as Image

In order to add or update an "Image" Field value of a Fusion Lifecycle item with the "Thumbnail" from Vault you can make use of the "_Thumbnail.Image" property from the powerVault File object.

For the following example we defined a new Image Field called "Thumbnail" in Fusion Lifecycle and added it to the 'Summary' section of the 'Items and BOMs' workspace.

Finally we extended the previous examples for adding and updating Fusion Lifecycle items with passing the Thumbnail  of the Vault file:

if (-not $item) {
$item = Add-FLCItem -Workspace $workSpace -Properties @{
...
"Thumbnail" = $file._Thumbnail.Image
}
} else {
$item = Update-FLCItem -Workspace $item.Workspace -ItemId $item.Id -Properties @{
...
"Thumbnail" = $file._Thumbnail.Image
}
}


Add DWF as attachment

Additionally an attachment can be uploaded to Fusion Lifecycle by using Add-FLCAttachment.

In this example all attachments from the file are retrieved from Vault, the DWF file is picked, then downloaded to TEMP and finally uploaded to Fusion Lifecycle:

$attachments = Get-VaultFileAssociations -File $file._FullPath -Attachments
$dwf = $attachments | Where-Object {$_._Extension -eq "dwf"}
$dwf = Save-VaultFile -File $dwf._FullPath -DownloadDirectory "C:\Temp"

$dwfAttachment = $item | Add-FLCAttachment -Path $dwf.LocalPath -Description $dwf._Description

Add or update BOM information

In order to update the BOM information of a Fusion Lifecycle item you need to first get the BOM from the Vault file and pass the items for all its components to the Update-FLCBOM cmdlet.

Similar as for the header item we can check using the Get-FLCItems cmdlet if the BOM components exists in Fusion Lifecycle, create them using Add-FLCItem or update them using the Update-FLCItem cmdlet.

We can set the "Unit of Measure" Field for the BOM line items with the units from the File BOM, but the Field should be defined as  BOM UOM Pick List in Fusion Lifecycle. 

$bomRows = @()

$fileBom = Get-VaultFileBom -File $file._FullPath
foreach ($fileBomRow in $fileBom) {
$childItem = (Get-FLCItems -Workspace $item.Workspace -Filter ('ITEM_DETAILS:ITEMID="{0}" ' -f $fileBomRow.'Bom_Part Number'))[0]
if (-not $childItem) {
$childItem = Add-FLCItem -Workspace $item.Workspace -Properties @{
"itemID" = $fileBomRow.'Bom_Part Number';
"Description" = $fileBomRow.Bom_Description;
"Unit of Measure" = $fileBomRow.Bom_Unit
}
} else {
$childItem = $childItem | Update-FLCItem -Properties @{
"Description" = "$($fileBomRow.Bom_Description), Updated"
"Unit of Measure" = $fileBomRow.Bom_Unit
}
}
$bomRows += @{
'Bom_PositionNumber'= $fileBomRow.Bom_PositionNumber
'Workspace' = $childItem.Workspace
'Id'= $childItem.Id
'Bom_Quantity'= $fileBomRow.Bom_Quantity
}
}

$FLCBom = $item | Update-FLCBOM -Rows $bomRows

Trigger Workflow automatically

By using powerJobs Processor you can automate your new custom Workflow to be triggered automatically e.g. on Vault Lifecycle changes to 'Released' states as described here.


Cover other use cases

If you need to do something in Fusion Lifecycle that is not covered using the existing powerFLC cmdlets you can directly use the Fusion Lifecycle REST API instead.


You can find more powerFLC workflows on coolOrange LABS on GitHub.

All those workflows can be used as a sample for creating your own custom Workflows.


See Also

Keep manually added bomRows in FLC (coolOrange knowledge base)

Using the Fusion Lifecycle Filter to search for items (coolOrange knowledge base)

Create a powerJobs Processor job (coolOrange wiki)

powerFLC cmdlets (coolOrange wiki)

powerVault File object (coolOrange wiki)