When working with Vault items in scripts it is often needed to update the item. In the Vault Client you can do this using the context menu on an item and clicking on "Assign/Update item".

The same can also be done by using the Vault API if you want to automate this procedure for example in a powerJobs Processor job.


Updating items via API

Create a new PowerShell script. If you plan to use this as a powerJobs Processor job you don't need to log into Vault.

Import-Module powerVault
$vault = "Vault"

$server = "localhost"
$user = "Administrator"
$password = ""
Open-VaultConnection -Vault $vault -Server $server -User $user -Password $password


After successfully logging into Vault you can use the Vault API via $vault.

The next step it to get an item that needs to be updated via API to be able to get the $item.RevIdĀ property:

$itemNumber = "Assembly1"
$item = $vault.ItemService.GetLatestItemByItemNumber($itemNumber)


The following code then finally updates the item and commits it:

$assignAll = [Autodesk.Connectivity.WebServices.ItemAssignAll]::Default
$autoAssignDuplicates = $true
$vault.ItemService.UpdatePromoteComponents($item.RevId, $assignAll, $autoAssignDuplicates)

[System.DateTime]$timestamp = New-Object -TypeName System.DateTime
$compOrder = $vault.ItemService.GetPromoteComponentOrder([ref]$timestamp)
$vault.ItemService.PromoteComponents($timestamp, $compOrder.PrimaryArray)
$itemsAndFiles = $vault.ItemService.GetPromoteComponentsResults($timestamp)

$items = $itemsAndFiles.ItemRevArray
$vault.ItemService.UpdateAndCommitItems($items)


See Also

Assign Items (Autodesk )