Issue

When an item changes lifecycle transition, a PDF of all associated drawings has to be created.


Solution

This sample code can be added to a specific item lifecycle transition. The code will get all drawings associated to the item and queue the sample PDF job delivered with powerJobs for each drawing. You can also queue your own job by changing the -Name parameter in the Add-VaultJob cmdlet.

if ($item) {
    $itemAssocs = Get-VaultItemAssociations -Number $item.Number
    $drawings = $itemAssocs | Where-Object { $_._Extension -eq 'dwg' -or $_._Extension -eq 'idw'}
    if ($drawings -ne $null) {
        foreach ($drawing in $drawings) {
            $addedJob = Add-VaultJob -Name "Sample.CreatePDF" -Description "Create PDF from drawings associated to item number '$($item.Number)'" -Parameters @{
                "EntityId" = $drawing.Id
                "EntityClassId" = $drawing.'Entity Type ID'
            }
        }
    }
    else {
        Write-Host "No drawing found for item '$($item.ItemNum)'"
        return 
    }
}
else {
    Write-Host "The job was not executed for an item"
    return
}


How to add a job on lifecycle transition

In order to automatically trigger a job on a lifecycle transition it has to be added to the lifecycle transition in Vault. To do so follow these steps:

  1. In Vault navigate to Tools, Administration
  2. Click on Vault settings, behaviors, lifecycles
  3. Select the required lifecycle and click on edit
  4. Select the starting status and the transition on which the job should be executed and click on edit
  5. Under 'Custom Job Types' click add and write the name of  the job without its *.ps1 extension in the dialog.


Remarks

Get-VaultItemAssociations (coolOrange wiki)

Add-VaultJob (coolOrange wiki)