Hi,
Whilst this is an old thread the issue has not yet been resolved. For the benefit of customers who require a WFA operator to be denied access to resuming a workflow that has been rejected\canceled by an approver, here an example of a WFA command that will ensure the workflow fails if the execution ID was previously canceled by an approver.
Param(
[Parameter(Mandatory=$True, HelpMessage="The WFA Server hostname")]
[String]$Hostname
)
#'------------------------------------------------------------------------------
#'Enumerate the MySQL root user credentials from the registry.
#'------------------------------------------------------------------------------
Try{
[Array]$options = $(Get-ItemProperty -Path "HKLM:\Software\Wow6432Node\Apache Software Foundation\Procrun 2.0\NA_WFA_SRV\Parameters\Java" -Name Options -ErrorAction Stop | Select-Object -ExpandProperty Options)
[String]$password = $options[$options.GetUpperBound(0) -1].Split("=")[1]
[Int]$jobId = $(Get-WfaRestParameter "jobId")
[String]$query = "SELECT `user`.name, `user`.user_role_type, job_history.`status`, job_execution.`status`, job_history.message FROM wfa.job_history, wfa.job_execution, wfa.`user` WHERE job_history.user_id = `user`.id AND job_history.job_execution_id = job_execution.id AND job_execution.id = $jobId"
}Catch{
Throw "Failed enumerating MySQL credentials from the registry on ""$Hostname"""
}
#'------------------------------------------------------------------------------
#'Raise an error if the WFA job ID or MySQL password are Null or empty.
#'------------------------------------------------------------------------------
If([String]::IsNullOrEmpty($jobId)){
Throw "Failed enumerating WFA Job ID"
}
If([String]::IsNullOrEmpty($password)){
Throw "Invalid MySQL credentials"
}
#'------------------------------------------------------------------------------
#'Invoke the SQL query for the WFA Job ID history.
#'------------------------------------------------------------------------------
Try{
$records = Invoke-MySqlQuery -Query $query -User root -Password $password -ErrorAction Stop
Get-WFALogger -Info -Message "Invoked SQL query ""$query"" for job ID $jobId"
}Catch{
Get-WFALogger -Error -Message $("Failed invoking SQL query ""$query"" for job ID $jobId. Error " + $_.Exception.Message)
Throw "Failed invoking SQL query for Job ID $jobId"
}
#'------------------------------------------------------------------------------
#'Raise an error if the workflow was previously canceled by an approver.
#'------------------------------------------------------------------------------
ForEach($record In $records){
[String]$status = $record.status
[String]$userRole = $record.user_role_type
[String]$message = $record.Message
If($status -eq "CANCELED" -And $userRole -eq "Approver"){
If([String]::IsNullOrEmpty($message)){
Throw $("Job ID $jobId was canceled by approver """ + $record.Name + """")
}Else{
Throw $("Job ID $jobId was canceled by approver """ + $record.Name + """ with comment """ + $message + """")
}
}
}
Get-WFALogger -Info -Message "Job ID $jobId was not previously canceled by an approver. Resuming workflow"
#'------------------------------------------------------------------------------
Note: Use can use this MVEL function to enumerate the WFA servers hostname EG call the function using single quotes: get_wfa_hostname('')
def get_wfa_hostname(hostname){
import java.net.InetAddress;
InetAddress addr = java.net.InetAddress.getLocalHost();
return addr.getHostName();
}
Hope that’s useful.
/Matt
If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.