I have done a workflow in my project but I have a problem when I click recall button it doesn't change the line status into draft again I tried to add an event handler class
final class CFM_Workflow_EventHandler
{
[FormControlEventHandler(formControlStr(WorkflowStatus, WorkflowStatusCancel), FormControlEventType::Clicked)]
public static void WorkflowStatusCancel_OnClicked(FormControl sender, FormControlEventArgs e)
{
FormRun formRun = sender.formRun();
// Get the current record from the form's data source
FormDataSource workflowTrackingStatusTable_ds = formRun.dataSource(formDataSourceStr(WorkflowStatus, WorkflowTrackingStatusTable));
WorkflowTrackingStatusTable workflowTrackingStatusTable = workflowTrackingStatusTable_ds.cursor();
// Retrieve the correlation ID
WorkflowTrackingStatusTable trackingTable;
select firstonly CorrelationId from trackingTable
where trackingTable.InstanceNumber == workflowTrackingStatusTable.InstanceNumber;
if (trackingTable.CorrelationId)
{
// Cancel the workflow
Workflow::cancelWorkflow(trackingTable.CorrelationId, "Cancelled by user via Recall button");
// Optional: Update your custom table status
ITRequestEqLine itRequestEqLine;
select forupdate itRequestEqLine
where itRequestEqLine.InstanceNumber == workflowTrackingStatusTable.InstanceNumber;
if (itRequestEqLine)
{
ITRequestEqLine::updateWorkflowStatus(itRequestEqLine.RecId, WorkflowLineStatusCFM::Draft);
}
info("Workflow has been successfully recalled.");
}
else
{
warning("Unable to find a valid workflow correlation ID.");
}
}
}
after I applied it the recall button became dimmed