Skip to content

Commit

Permalink
Worklow Status Manageement : use Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Aymeric Mouillé committed Jan 6, 2025
1 parent 39bd8a4 commit 0acb807
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
14 changes: 5 additions & 9 deletions src/Workflows/Disable-XrmWorkflow.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,11 @@ function Disable-XrmWorkflow {
Trace-XrmFunction -Name $MyInvocation.MyCommand.Name -Stage Start -Parameters ($MyInvocation.MyCommand.Parameters);
}
process {

$workflowReference = New-XrmEntityReference -LogicalName "workflow" -Id $WorkflowId;
# TODO : Use Update
$request = New-Object -TypeName Microsoft.Crm.Sdk.Messages.SetStateRequest;
$request.EntityMoniker = $workflowReference;
$request.State = New-XrmOptionSetValue -Value 0;
$request.Status = New-XrmOptionSetValue -Value 1;

Invoke-XrmRequest -XrmClient $XrmClient -Request $request | Out-Null;
$workflowUpdate = New-XrmEntity -LogicalName "workflow" -Id $WorkflowId -Attributes @{
"statecode" = New-XrmOptionSetValue -Value 0
"statuscode" = New-XrmOptionSetValue -Value 1
}
Update-XrmRecord -XrmClient $XrmClient -Entity $workflowUpdate;
}
end {
$StopWatch.Stop();
Expand Down
14 changes: 5 additions & 9 deletions src/Workflows/Enable-XrmWorkflow.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,11 @@ function Enable-XrmWorkflow {
Trace-XrmFunction -Name $MyInvocation.MyCommand.Name -Stage Start -Parameters ($MyInvocation.MyCommand.Parameters);
}
process {

$workflowReference = New-XrmEntityReference -LogicalName "workflow" -Id $WorkflowId;
# TODO : Use Update
$request = New-Object -TypeName Microsoft.Crm.Sdk.Messages.SetStateRequest;
$request.EntityMoniker = $workflowReference;
$request.State = New-XrmOptionSetValue -Value 1;
$request.Status = New-XrmOptionSetValue -Value 2;

Invoke-XrmRequest -XrmClient $XrmClient -Request $request | Out-Null;
$workflowUpdate = New-XrmEntity -LogicalName "workflow" -Id $WorkflowId -Attributes @{
"statecode" = New-XrmOptionSetValue -Value 1
"statuscode" = New-XrmOptionSetValue -Value 2
}
Update-XrmRecord -XrmClient $XrmClient -Entity $workflowUpdate;
}
end {
$StopWatch.Stop();
Expand Down

0 comments on commit 0acb807

Please sign in to comment.