Script repository

Approval requests approved during the last X days

Updated on: Jan 18, 2026, Views: 5933

Approval requests

The script e-mails a report on approval requests approved during the specified number of days. To execute the script, create a scheduled task configured for the Domain object type. The Activity Scope should include any managed domain. The domain will not determine the scope of approval requests to check and will only be used to execute the scheduled task.

Parameters

  • $numDays - the number of days to include the requests into the report for.
  • $to - email addresses of the report recipients.
  • $subject - the email notification subject.
  • $reportHeader - the email notification header.
  • $reportFooter - the email notification footer.
$numDays = 7 # TODO: modify me
$to = "recipient@example.com" # TODO: modify me
$subject = "Requests approved during the last $numDays days" # TODO: modify me
$reportHeader = "<b>Approved operations:</b><br/><br/>" # TODO: modify me
$reportFooter = "<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

# Bind to the 'Approval Requests' container.
$approvalsPath = $Context.GetWellKnownContainerPath("ApprovalRequests")
$aprovalsContainer = $Context.BindToObject($approvalsPath)

# Get approved requests.
$requests = $aprovalsContainer.GetApprovalRequests("ADM_APPROVALSTATE_APPROVED")

# Get default web interface address.
$webInterfaceAddress = "%adm-WebInterfaceUrl%"
if ([System.String]::IsNullOrEmpty($webInterfaceAddress))
{
    $Context.LogMessage("Default web interface address not set for Adaxes service.", "Warning") # TODO: Modify me
}

$sendMail = $False
$modificationDate = (Get-Date).AddDays(-$numDays)
$approvedTasks = "<ol>"

# Find recently modified requests.
foreach ($requestID in $requests)
{
    $guid = New-Object "System.Guid" (,$requestID)
    $guid = $guid.ToString("B")
    $requestPath = "Adaxes://<GUID=$guid>"
    $request = $Context.BindToObject($requestPath)
    
    $requestModificationDate = ($request.Get("whenChanged")).ToLocalTime()

    if ($requestModificationDate -lt $modificationDate)
    {
        continue.
    }
    
    # Add requests to the report.
    $requestOperation = $request.DescriptionOfOperationToApprove
    $processedBy = [Softerra.Adaxes.Utils.ObjectNameHelper]::GetObjectName($request.ProcessedBy, 'IncludeParentPath')
    $approvedTasks += "<li>Operation: $requestOperation<br/> Processed By: $processedBy<br/> Date: $requestModificationDate<br/><a href='$webInterfaceAddress`#/Browse/$guid'>Details</a></li>"
    
    $sendMail = $True
}
$approvedTasks += "</ol>"

if (-not($sendMail))
{
    $Context.LogMessage("No requests matching the criteria.", "Information") # TODO: Modify me
    return
}

# Send mail
$report = $reportHeader + $approvedTasks + $reportFooter
$Context.SendMail($to, $subject, $NULL, $report)

Comments 0

You must be signed in to comment.

    Got questions?

    Support Questions & Answers

    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.