We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.

Script repository

Delegate approvals to assistants and secretaries

The script allows delegating the operations a user needs to approve to their assistants or secretaries. When run, the script adds a user's assistant or secretary as an additional approver of all pending requests that the user can approve.

To delegate approval requests, create a custom command that runs the script and run it on the user or users whose requests you want to delegate. To add the script to your command, use the Run a program or PowerShell script action.

Parameter:

  • $newApproverDNProperty - Specifies the property that contains the subtitle approver. Use assistant or secretary.
See Also: Remove assistants and secretaries from Approval Requests.
Edit Remove
PowerShell
$newApproverDNProperty = "assistant" # TODO: moidfy me

# Get the new approver DN
try
{
    $newApproverDN = $Context.TargetObject.Get($newApproverDNProperty)
}
catch
{
    $Context.LogMessage("Property '$newApproverDNProperty' is empty", "Warning") # TODO: modify me
    return
}

# Get all requests awaiting for approval by user
$requests = $Context.TargetObject.GetApprovals("ADM_APPROVALSTATE_PENDING")
if ($requests.Length -eq 0)
{
    return # No requests awaiting for approval by the user
}

# Bind to the new approver
$newApprover = $Context.BindToObjectByDN($newApproverDN)

# Add the new approver to each request
foreach ($requestID in $requests)
{
    # Bind to the request
    $requestGuid = [Guid]$requestID
    $path = "Adaxes://<GUID=$requestGuid>"
    $request = $Context.BindToObject($path)
    
    # Get approvers info
    $approversInfo = $request.GetApproversInfo()
    
    # Check whether the new approver is already an approver for the current request
    if ($approversInfo.IsApproverEx($newApprover, $request.Requestor, $request.TargetObject))
    {
        continue
    }

    # Add the new approver
    $approverTrustees = $approversInfo.ApproverTrustees
    $approverTrustees.Add($newApprover)
    
    # Update the approvers list
    $request.SetApproversInfo($approversInfo)
    $request.SetInfo()
}
Comments 0
Leave a comment
Loading...

Got questions?

Support Questions & Answers