Workflow routing if invalid destination user


Badge +2

I have a workflow that can vary depending upon a value where it go anywhere from 1-10 approvers.  To do this, I have my seed values surfaced using a SharePoint list and allow them to populate the number of approvers for that request type,  Ex. Column: Approver1, Value: username .  At runtime, I set the destination user for each activity using the value retrieved from the SharePoint list.  I was thinking that if the value of the next approver was blank(null) we could route the processinstance to Completed.

 

It possible to check for this and redirect using a preceding rule for each activity?  That way it would still evaluate whether or not an actual destination user would exist if someone were to Override and use the WorklistItem Redirect function?

 

I know I could evaluate this during the Outcomes but wanted to know if there was a better way.


5 replies

Userlevel 1
Badge +8

Hi tuffmoyrongsafe

 

The preceding rule option will only allow you to configure a rule to start the activity, it wont give you an option to move to another activity.  If you  move to an activity expecting a destination user (i.e. has a task event) and the destination user is empty, the process will move to an error state, so you need to either prevent that happening or handle it if it does.

 

I think there are 2 ways you can approach this.

 

1. Create an activity before the Approval activity that checks the value of the next approver. If it is not blank then configure a line to move to the approval activity (using a line rule). If it is blank then you can either finish the process (i.e. go no-where) or move to the next appropriate activity. The downside of this approach is that if someone uses the redirect action this would result in an error.

 

2. Enable exception rules for the activity. This will involve writing some code to handle an exception where there is no destination user for the activity (i.e. the approver is blank). You will need to use Visual Studio and have some understanding of the K2 api to do what you want (e.g. goto another activity or finish the process)

Badge +8

You're making this way more complicated than it needs to be.  To handle variable destinations like this, use an XML field.  Then configure your activity as a plan per destination and use the XML field as the destination.  With this configuration, you can use whatever logic you want to build the XML field that contains your approvers and K2 will dynamically assign activities based on the number of nodes in your XML field.

Badge +2
The problem with using an xml field is having to change it when it's invalid. if it's invalid, what happens? The process errors out and you need to modify the data field for that activity instance.

It's easier to change the destination user from from a more accessible source and redirect /restart that process instance to the appropriate activity.
Badge +2
@Andrew. Thanks for your info. I figured using both of those solutions but wanted to know if there was a better way. I think I'll go with option 2 as it will deal with the in flight process instances that have destination users that have been disabled.
Badge +8

The XML field is constructed dynamically by your process based on the parameters you determine.  If the XML field is "invalid" then your process is broken. 

 

The road you are headed down will leave you with a mess of unfinished activites and errored processes.

Reply