I use a sub-workflow with 'wait until finished' cleared to contain optional tasks. This works fine, but at a downstream point in the main workflow, I want to set the optional tasks as closed and completed in code (not script) if the user chose not to execute these. My workflow looks something like this:
Start A
Task A1
Sub-workflow B
Start B
Task B1
Task B2
End B
Task A2
Task A3 <--- At this point I want to set B tasks to complete
..... rest of workflow
Sub-workflow B, Task B1 and Task A2 are created at the same time, which is what I want. I can catch the point at which I want to terminate Sub-workflow B in the OnTaskCreated event of Task A3. I have tried changing statuses of Tasks B1 and B2 to their completion statuses in this event. It works for B1, but B2 has not yet been created at this point. How can I finish entire Sub-workflow B at this point?