Script repository
The scripts notify users about approval requests awaiting their decision. To execute the script, create a scheduled task configured for the Domain object type and add a managed domain to the Activity Scope of the task. The domain will only be used to trigger execution of the scheduled task.
Script 1: Separate email for each approval request
This script resends the default notifications for pending requests to their approvers.
# Bind to the 'Approval Requests' container.
$containerPath = $Context.GetWellKnownContainerPath("ApprovalRequests")
$container = $Context.BindToObject($containerPath)
# Get all pending approval requests.
$requests = $container.GetApprovalRequests("ADM_APPROVALSTATE_PENDING")
foreach ($requestID in $requests)
{
# Bind to the approval request.
$guid = New-Object "System.Guid" (,$requestID)
$guid = $guid.ToString()
$requestPath = "Adaxes://<GUID=$guid>"
$request = $Context.BindToObject($requestPath)
# Resend notification to approvers.
$request.NotifyApprovers()
}Script 2: Single notification for all approval requests
For each approver, this script sends a single notification containing information on all the pending approval requests awaiting their decision.
Parameters
$notificationHeader- the email notification header.$notificationFooter- the email notification footer.$subject- the email notification subject.
$notificationHeader = "<b>List of unapproved operations:</b><br/><br/>" # TODO: modify me
$notificationFooter = "<hr /><p><i>Please do not reply to this e-mail, it has been sent to you for notification purposes only.</i></p>" # TODO: modify me
$subject = "Operations Awaiting Your Approval" # TODO: modify me
# Bind to the Approval Requests container
$containerPath = $Context.GetWellKnownContainerPath("ApprovalRequests")
$container = $Context.BindToObject($containerPath)
# Get all pending approval requests
$pendingRequests = $container.GetApprovalRequests("ADM_APPROVALSTATE_PENDING")
$requests = @{}
foreach ($requestID in $pendingRequests)
{
# Bind to the approval request
$requestGuid = New-Object "System.Guid" (,$requestID)
$requestGuid = $requestGuid.ToString()
$requestPath = "Adaxes://<GUID=$requestGuid>"
$request = $Context.BindToObject($requestPath)
# Get information on the operation awaiting approval
$requestInfo = New-Object PSObject
$requestInfo | add-member Noteproperty Guid $requestGuid
$requestInfo | add-member Noteproperty Operation $request.DescriptionOfOperationToApprove
# Get information on the approvers
$approversInfo = $request.GetApproversInfo()
$approvers = $approversInfo.GetApproversEx($request.Requestor, $request.TargetObject)
foreach ($approver in $approvers)
{
try
{
$mail = $approver.Get("mail")
}
catch
{
continue
}
if (-not($requests.ContainsKey($mail)))
{
$requests.Add($mail, @($requestInfo)) | Out-Null
continue
}
$requests[$mail] += $requestInfo
}
}
# Get default Web Interface address
$webInterfaceAddress = "%adm-WebInterfaceUrl%"
if ([System.String]::IsNullOrEmpty($webInterfaceAddress))
{
$Context.LogMessage("Default web interface address not set for the Adaxes service.", "Warning")
}
foreach ($mail in $requests.Keys)
{
# Add all requests to e-mail
$unapprovedTaskList = "<ol>"
foreach ($requestInfo in $requests[$mail])
{
$requestGuid = $requestInfo.Guid
$requestOperation = $requestInfo.Operation
$unapprovedTaskList += "<li><a href='$webInterfaceAddress`#/Browse/$requestGuid'>$requestOperation</a></li>"
}
$unapprovedTaskList += "</ol>"
# Build email notification
$htmlBody = $notificationHeader + $unapprovedTaskList + $notificationFooter
# Send notification to approver
$Context.SendMail($mail, $subject, $NULL, $htmlBody)
}
Comments 2
You must be signed in to comment.
Ben Cavo
I would like not to include 'DescriptionOfOperationToApprove' on the mail, how would I add just the name of the user that was created?
Thanks
Support
Hello Ben,
Unfortunately, there is no such possibility using the script from this article. It can only be done using a custom script the will send a custom email not the automatically generated one.