Hello,
You have 2 approaches.
-
Use the “InvokeScriptAspect” option
<InvokeScriptAspect Identifier="Directory_User_InvokeScript" Agent="Default" ScriptFile="C:/Usercube/Scripts/InvokeAspects/aspect.ps1">
<PointCut Activity="Directory_User_StartInternal:Request" ActivityState="ActionWithRefine-Executed" Mode="After" />
<PointCut Activity="Directory_User_StartExternal:Request" ActivityState="ActionWithRefine-Executed" Mode="After" />
</InvokeScriptAspect>
You need a job to run in order to execute the script:
<Job Identifier="InvokeAspects" DisplayName_L1="Invoke Aspects" Agent="Local">
<InvokeAspectsTask Agent="Default" DisplayName_L1="Execute Powershell for aspects" OutputPath="C:/Usercube/Temp" OpenIdClient="Job" />
</Job>
Then you need to configure your script to process workflow instances and send Teams notifications.
#
param(
[Parameter(Mandatory = $true)][string]$instancesPath
)
echo $instancesPath
$instances = Import-CSV -Delimiter ';' -Encoding UTF8 -Path $instancesPath
echo $instances.Count
# PS code to send Teams notification for each instance....
#
-
Use a “InvokeExpressionTask” option
<Job Identifier="SendTeamsNotifications" DisplayName_L1="Send Teams Notification" Agent="Local">
<InvokeExpressionTask Identifier="SendTeamsNotifications" DisplayName_L1="Send Teams Notification" InputPath="C:/Usercube/Scripts/SendTeamsNotification.ps1" ContinueOnError="1" Level="0" />
</Job>
The script can be schedule to run daily for example.
In the script you can call Identity Manager APIs to list pending requests of the day (Get workflows instances that has been created that day) and send teams notifications.
The API call should look like this :
$api = "http://localhost:5000"
# Credentials
$apiId = "Job@localhost"
$apiSecret = "secret"
cd C:\Usercube\Runtime
# Body for Token request
$Body = @{
'client_id' = $apiId
'client_secret' = $apiSecret
'scope' = 'usercube_api'
'grant_type' = 'client_credentials'
}
# Parameters for Token request
$Params = @{
'Uri' = "$api/connect/token"
'Method' = 'Post'
'Body' = $Body
'ContentType' = 'application/x-www-form-urlencoded'
}
# Get the Bearer Token
$AuthResponse = Invoke-RestMethod @Params
# Hearders for GET requests
$Headers = @{
'Authorization' = "Bearer $($AuthResponse.access_token)"
}
# Headers for POST/PUT Requests
$PostHeaders = @{
'Authorization' = "Bearer $($AuthResponse.access_token)"
'Content-Type' = "application/json"
}
$Url = "http://localhost:5000/api/Workflows/WorkflowInstance?api-version=1.0&squery=join Workflow w join CurrentActivityInstance ai join ai.Performer of type Directory_User perf join Workflow_Directory_User:Directory_User Directory_User join Directory_User.MainRecord Directory_UserMainRecord join Directory_UserMainRecord.Title Directory_UserMainRecordTitle join Directory_UserMainRecord.Organization Directory_UserMainRecordOrganization join Directory_UserMainRecord.Site Directory_UserMainRecordSite join Directory_User.ResourceRiskScore Directory_UserResourceRiskScore top 12 select Id, Identifier, IsCompleted, CurrentStateId, w.DisplayName, w.Identifier, ai.Subject, ai.ChangeSetSummary, ai.CreationDate, perf.InternalDisplayName, perf.Id,Directory_UserMainRecord.FirstName,Directory_UserMainRecord.LastName,Directory_UserMainRecordTitle.DisplayName,Directory_User.Id,Directory_User.PhotoTag,Directory_UserMainRecordOrganization.DisplayName,Directory_UserMainRecordSite.DisplayName,Directory_UserResourceRiskScore.Score where (ai.CreationDate>=%222026-05-06T22:00:00.000Z%22) order by ai.CreationDate desc, Id desc&Path=/Workflows/WorkflowInstance/Supervise&QueryRootEntityType=Workflow_Directory_User"
$Result = (Invoke-RestMethod -Headers $Headers -Uri $Url).Result
Regards
Hazem