Hello,
We've modified the script to handle such situations. The version of the script that you can find below will not cause such an error. Also, it will send a notification e-mail to an administrator so that appropriate action can be taken.
Parameters in the script:
- $requestExpirationDays - specifies the number of days an Approval Request needs to remain pending to become outdated.
- $adminMail - specifies the administrator's e-mail address.
- $noApproversMailSubject - specifies the subject of the notification message.
- $noApproversMailTemplate - specifies a template for the notification message. In the template, {0} will be replaced with a link to the approval request that triggered the notification.
$requestExpirationDays = 3 # TODO: modify me
$adminMail = "AdminMail@domain.com" # TODO: modify me
$noApproversMailSubject = "A request without approvers has been found" # TODO: modify me
$noApproversMailTemplate = "<b>The following approval request does not have any approvers:</b><br/>{0}<br/>Please take appropriate action.<hr /><p><i>Do not reply to this e-mail, it has been sent to you for notification purposes only.</i></p>" # TODO: modify me
# Sets new aprovers for the request and sends out e-mail notifications
function HandleExpiredRequest($request, $adminMail, $subject, $webInterfaceAddress, $message)
{
$approversInfo = $request.GetApproversInfo()
$approvers = $approversInfo.GetApproversEx($request.Requestor, $request.TargetObject)
$trustee = $approversInfo.ApproverTrustees
# Send mail to admin if request does not have approvers
if ($approvers.Count -eq 0)
{
$requestGuid = [Guid]$request.Get("objectGuid")
$requestDescription = $request.DescriptionOfOperationToApprove
$requestLink = "<a href='$webInterfaceAddress`ViewObject.aspx?guid=$requestGuid'>$requestDescription</a>"
$message = [System.String]::Format($message, $requestLink)
$Context.SendMail($adminMail, $subject, $NULL, $message)
return
}
if ($approvers.Count -gt 1)
{
return
}
$approver = $approvers.GetObject(0)
try
{
$newApproverDNs = $approver.Get("seeAlso")
}
catch
{
return # No new approvers specified
}
foreach ($approverDN in $newApproverDNs)
{
$approver = $Context.BindToObjectByDN($approverDN)
if ($approversInfo.IsApproverEx($approver, $request.Requestor, $request.TargetObject))
{
continue
}
$trustee.Add($approver)
}
$request.SetApproversInfo($approversInfo)
$request.SetInfo()
}
# 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")
# Get the default Web Interface address
$webInterfaceAddress = "%adm-WebInterfaceUrl%"
if ([System.String]::IsNullOrEmpty($webInterfaceAddress))
{
$Context.LogMessage("Default web interface address not set for Adaxes service. For details, see http://www.adaxes.com/help/?HowDoI.ManageService.RegisterWebInterface.html", "Warning")
}
foreach ($requestID in $requests)
{
# Bind to the approval request
$guid = [Guid]$requestID
$request = $Context.BindToObject("Adaxes://<GUID=$guid>")
# Check whether the request has expired
$requestExpDate = $request.CreationDate.AddDays($requestExpirationDays)
if ([System.DateTime]::Now -lt $requestExpDate)
{
#continue
}
HandleExpiredRequest $request $adminMail $noApproversMailSubject $webInterfaceAddress $noApproversMailTemplate
# Send additional email to approvers
$request.NotifyApprovers()
}