Script Repository


Delegate approvals to assistants and secretaries

September 23, 2016
1208

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 )
No results found.
Leave a comment