Script repository

Export approval request to CSV

Updated on: Jan 18, 2026, Views: 5794

Export data, Approval requests

The script exports approval request information to a CSV file once an approval request is approved, denied or cancelled. To execute the script, create a business rule triggering After updating a ApprovalRequest.

In the script, the $csvFilePath variable specifies the path to the CSV file that will store information on the approval request.

$csvFilePath = "\\Server\share\ApprovalRequests.csv" # TODO: modify me

# Build a new row for the CSV file.
switch ($Context.TargetObject.ApprovalState)
{
    "ADM_APPROVALSTATE_PENDING"
    {
        return
    }
    "ADM_APPROVALSTATE_APPROVED"
    {
        $state = "Approved"
    }
    "ADM_APPROVALSTATE_DENIED"
    {
        $state = "Denied"
    }
    "ADM_APPROVALSTATE_CANCELED"
    {
        $state = "Canceled"
    }
}

$reportEntry = New-Object PSObject
$reportEntry | Add-Member -Name "State" -Value $state -MemberType NoteProperty
$reportEntry | Add-Member -Name "Requestor" -Value $Context.TargetObject.Requestor.Get("name") -MemberType NoteProperty
$reportEntry | Add-Member -Name "Processed By" -Value $Context.TargetObject.ProcessedBy.Get("name") -MemberType NoteProperty
$reportEntry | Add-Member -Name "Creation Date" -Value $Context.TargetObject.CreationDate -MemberType NoteProperty
$reportEntry | Add-Member -Name "Target Object" -Value $Context.TargetObject.TargetObject.Get("name") -MemberType NoteProperty

if ($state -ne "Approved")
{
    $denialOrCancelingReason = $Context.TargetObject.DenialOrCancelingReason
}
else
{
    $denialOrCancelingReason = ""
}

$reportEntry | Add-Member -Name "Denial or Canceling Reason" -Value $denialOrCancelingReason -MemberType NoteProperty
$reportEntry | Add-Member -Name "Operation Description" -Value $Context.TargetObject.DescriptionOfOperationToApprove -MemberType NoteProperty

# Import the CSV file.
try
{
    [System.Object[]]$rows = Import-Csv $csvFilePath
}
catch
{
    $rows = $NULL
}

# Add a new row to the CSV file
if ($rows)
{
    $rows += $reportEntry
}
else
{
    $rows = $reportEntry
}

# Save changes
$rows | Export-Csv -Path $csvFilePath -NoTypeInformation

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.