Cancel a Workflow Task through an EventHandler

Keyser_Soze
New Contributor III

Hello there,

As the title implicates, I am trying to cancel the current running workflow task through a Business Rule (Transformation EventHandler). My workflow is the ETL process (Import, Validate, Load), I wrote an event handler to catch all rejects from 'Transformation' and 'Validation' steps then updates the Transformation Rules to ByPass these rejects.
My problem is the following: 

- After positioning myself on the event: BREventOperationType.Transformation.ValIntersect.FinalizeValidateIntersect, I execute a code that catches the validation rejects & updates the transformation rules accordingly. However, when I 'Revalidate/ReTransform' I get an error saying [ Workflow Unit already has a running task [ValidateTransformation - WP#TestWF.Import:S#Actual:T#2022M10], cannot start task [ValidateIntersections - WP#TestWF.Import:S#Actual:T#2022M10] until current task completes.]

Is it possible to modify a task's status to 'Completed' so I can relaunch the validation a second time ? If not what might be the best approach ? 

Thanks in advance

3 REPLIES 3

JackLacava
Community Manager
Community Manager

I don't think you can do what you're trying to do, because you're effectively still inside the original validation process when you handle events.

If you really want to automatically create these bypass (which tbh I wouldn't recommend, as you might end up not having auditing entries showing who created which bypass - not all APIs will produce an audit trail...), I would do so in the event handler but then just let the process return a failure anyway. The user would then re-trigger validation and this time be successful. Maybe drop a message somewhere mentioning that changes have been made so the user should try again.

Thanks for the precious reply,
The thing is we want to automate the whole ETL process without having any errors during the process. At the end of the ETL process, a file gets generated mentioning all the changes applied with WF PoV (Time,Scenario, ProfileName), all the bypassed rows and values and the username/Time of Execution. The audit part is not a main concern for the moment.
Can I achieve this using the 'ExecuteFileHarvestBatch()' instead of 'BRApi.Import.Process.ValidateTransformation/ValidateIntersections' ? If the batch encounters an errors, it will update the transformation rules & then relaunch the batch ? 
 

It's probably doable, but it will require some wrapping. For example, you could trigger the batch from a rule with a Data Management Sequence scheduled to retry (up to 3 times); the event handler will pick up errors, deal with them, then return an error; your Data Manager sequence will just retry, and the second (or third) time it should go through.

It might be possible to do all that within the wrapping Extender rule too, but I'm not sure and unfortunately I don't have time to try it this week.