Hello,
I've been looking for a long while to perform some actions when an approval has been denied.
Since i finally managed to get it done, i might as well share how to do it. :)
We have an automatic deprovisioning setup based on a date in attribute extensionattribute13 and the description of the user gets changed to 'waiting for approval when the approval is send, but it never got deleted. So here is my example on how to fix that issue automatically:
Create a business rule with the trigger AfterUpdating an Approval Request
Add a condition based on a powershell script. This script contains the following:
$approved = $Context.GetModifiedPropertyValue("adm-ApprovalState")
if($approved -eq 2){
$Context.ConditionIsMet = $true
}
This will make the rule only triggers or denied approvals
Now we need to add an action run powerhsell script with the following code (Needs to be adapted to your situation of course)
import-module Adaxes
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")
$admNS = New-Object("Softerra.Adaxes.Adsi.AdmNamespace")
$admService = $admNS.GetServiceDirectly("localhost")
$path = $Context.TargetObject.AdsPath
$request = $admService.OpenObject($path, $NULL, $NULL, 0)
[XML]$xml = $request.DescriptionOfOperationToApproveXml
$requestor = $request.requestor.get("name")
### u can add another conditon to only execute the business rule based on the requestor
### Retract all the objects contained in the approval request
$targets = $xml.message.objectname
$targets = @($targets)
### First object is my scheduled task, so i need the 2nde object (the user)
[STRING]$target =$targets[1]
### need to retract the username out of the string
$target = $target.trimend(")")
$target = $target.split("(")[0].trimend(" ")
### get the DistinguishedName of the user we perfomed the approval on
$dn = (get-admuser -filter {name -eq $target}).DistinguishedName
### Clear the attributes because of the denied deprovisioning
Set-AdmUser $dn -Clear description,extensionAttribute13
$context.LogMessage("Description + end date cleared for user : $target ", "Information")
To get the the username out of the XML message u will need to do some testing on what XML message u get back from the approval request.
(For me it was the 2nd part of the array ( [STRING]$target =$targets[1]) because the first object was the scheduled task that called the approval request)
Hope it might help some other people out. ;)