In a PowerShell script you can use the Connect-FLC cmdlet to connect to Fusion Lifecycle with your credentials.

When using a custom workflow in powerJobs Processor the Fusion Lifecycle information can be retrieved using $tenant and $workflow as described in this article.

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


By using powerJobs Processor you can automate your new custom workflow directly on the Job Processor by simply creating a custom job out of the previous PowerShell script.

The job can be configured to be added to the Job Queue for the required Vault Lifecycle transitions.


Cover other use cases

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


Additional workflows

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

The workflows can be used as a basis for your own project.


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)