Add-VaultRestriction locks the ECO

When adding a Vault restriction using Add-Vaultrestriction the ECO is locked for 30 minutes

Issue

powerEvents Change Order events leave the Change Order in edit mode when using the powerEvetns Add-VaultRestriction Cmdlet to throw restrictions

Cause

The issue is caused by Add-VaultRestriction throwing a restriction on the Client side and not canceling the Change Order activity after throwing the restriction

Solution

To avoid this issue you can cancel the Change Order activity after throwing a restriction in the code. This example registers an "UpdateChangeOrderState" event, throws a restriction and then cancels the Change Order activity using the previously fetched "activityId" and the Change Order Id:

Register-VaultEvent -EventName UpdateChangeOrderState_Restrictions -Action 'RestrictUpdateChangeOrderState'
function RestrictUpdateChangeOrderState($changeOrder, $activity, $comments, $emails, $successful) {
Add-VaultRestriction -EntityName $changeOrder._Name -Message "This is a restriction"
$vault.ChangeOrderService.CancelChangeOrderActivity($changeOrder.Id, $activityId)
}

See Also

Change Order Events

Add-VaultRestriction