Amit V

Hi All

I have a sequential approval workflow. I am using replicator around createTask activity to assign multiple approvers.

Now If user wants to change approvers how should I use UpdateTask method Do I need to use replicator around update task as well

If someone can help me changing multiple approvers that would be great.

Best Regards




Re: SharePoint - Workflow Modifying Approvers

MarkAtDLC

You actually should use the Workflow Modification activities. The is an example in the Enterprise Content Management Starter Kit - I think it's called ModifyForm or something similar.

Basically you need to have an EventHandlingScope activity. Inside this activity you need:
1) An EnableWorkflow Modification activity with it's token set to the event handling scope
2) A Sequence containing the portion of the workflow over which the approvers are modifiable

By right clicking on the EventHandlingScope activity you will see Event Handlers in the list. Into the resulting displayed control you need to drag an OnWorkflowModified activity. It is in the invoked method of this activity that you will receive the updated approver and can set it on the task.

You will need to create a form (if you don't already have one) and modify your workflow.xml to use it for workflow modification.

The ECM kit's sample project fleshes all of this out.




Re: SharePoint - Workflow Modifying Approvers

Amit V

Hi mark

Thanks for your reply.

Actually I have done everything you mentioned above. I did look at the ECM sample replicate the same thing in my project. Now in ECM sample project they have shown how to update one Approver. So it was just one reviewer.

Now in my case Originator can multiple Approvers. I am using replicator around CreatTask activity to handle this multiple approvers. So for example Originator had 3 approvers in the beginning. Now Originator want to remove one of the 3 approvers and add another approver.

How do I update multiple approvers. Do I need to use replicator around modification piece of the workflow

Thanks for your help.

Regards






Re: SharePoint - Workflow Modifying Approvers

MarkAtDLC

I haven't actually tried this but I would think from the workflow creation perspective the easiest way to do it would be to encompass (inside the replicator) all of the workflow that can execute while the approver can change (that is, if you haven't already encapsulated it in a composite activity), then to put the EventHandlingScope Activity around that - again inside the replicator (as I think you were suggesting). However, this leaves a bit to be desired as application functionality - if your users must be able to change any number of approvers at the same time from the same modification page, this won't do that. More importantly, there would be one link per approver on the workflow modification page - and I don't think that you can customize the link title based on task properties - if not you end up with 1...n identical link titles, so the user has to try modification links on the workflow status page until they find the one that correponds to the task they want. Obviously not user-friendly functionality if this is indeed the case.

You can also create something that allowed you to put the replicator (maybe encased in a Sequence Activity ) in the EventHandlingScope activity. Either the workflow or the workflowproperties - I forget which - has access to the workflow task list, so if your custom page returns adequate information (i.e. taskId Guid) you can change tasks outside of the scope of the replicator - you just need to make sure that each task you try to modify is still modifiable (in the context of both code and business rules). I am just finishing a workflow that will allow the Originator to recall the item on which the workflow is based if it has not made it all of the way through the approval process, and as part of that I am retrieving the workflow's tasks from the outside of the replicator context and checking their state to see if they need to be cancelled, so I do have some experience with accessing tasks outside of the replicator, although my case is probably simpler since this functionality is only accessed once the replicator's Until condition has been met. Since your workflow will still be in the replicator when you modify your activity/ies, probably in the OnTaskChanged activity I believe this might prevent you from using SPListItem.Update, but there is another method to call within the workflow that you can use (SPWorkflowTask.AlterTask(...)). You will also need to explicity provide the information for all modifiable tasks to your custom form using EnableWorkflowModification.ContextData. This property, in the words of msdn "Gets or sets the context data to be passed to the modification form upon launch". Don't have experience using this property to pass information to the modification form, so I can't really tell you any more about it.

The main problem I had when I first tried this was that I couldn't access the correlation token of any replicator-created task outside of the replicator. Then I came across a blog entry (don't have link with me) that just used a code activity to change the tasks. In this context you can change as many tasks as you wish, depending upon how many task id's are returned from your form. The main hurdle there for me was that I was saving the taskId Guid from CreateTask as the identifier from within the replicator and forgot that it corresponded to the contents of the GUID field on the task list (so you will need a CAML query to retrieve the associated task) and that it isn't the same Guid used when accessing an item via the spListItem[guid] notation (as any normal person would assume).





Re: SharePoint - Workflow Modifying Approvers

MarkAtDLC

I just needed to perform a sanity check and ask a simple question here. You've probably already thought about this and have a good reason for not using it, but here it is anyway...

Have you considered using OnTaskChanged to change the AssignedTo property when the task approver changes If you don't need to support a change in the total number of approvers, then this could be much easier. Putting an OnTaskChanged event in a while loop inside your replicator after the CreateTask activity and making your workflow modification form a task edit form would allow your originators to use the edit task option to change the approver for each task (you probably already have this for the approver's part - you would just need to use before & after properties to detect what was changed in order to determine appropriate responses). It means your edit task page has to have logic to detect who is editing the task so that originators can't perform approval actions - but changing the approver seems to more specifically be a task edit than a workflow modification. It would probably also mean that the approver & originator edit functionalities would be modularized into server or ascx controls to make them easier to swap out based on the task editor's role. The one caveat is that I don't know if Sharepoint will send out the emails you might expect when the AssignedTo property is altered.




Re: SharePoint - Workflow Modifying Approvers

Amit V

Hi Mark

Thanks for your detailed replies. I am doing some testing on my dev environment to update task using custom code as you mentioned earlier. I think that might help, not too sure though.

It was a good thought to use OnTaskChanged event to update assignTo property. There are couple reasons I wont use this option.

1) I might have to support change in total number of approvers.

2) Originator has to go and change each task.

First I am going to test using replicator around EventHandlingScope. If that won't help then will try with custom code and see if that helps.

I will keep you updated with the results.

Thanks for continuous help.

Best Regards






Re: SharePoint - Workflow Modifying Approvers

Amit V

Hi Mark

I created task modification activities. When I click the Update link for workflow. I get the following error while loading infopath form.

The Root Element is missing.

I am not too sure what is causing this error. Any help would be greatly appreciated.

Regards

Amit






Re: SharePoint - Workflow Modifying Approvers

MarkAtDLC

The EnableWorkflowModification activity has a ContextData property. This property must contain XML that conforms to the schema associated with your form. See: http://msdn2.microsoft.com/en-us/library/ms550177.aspx near the bottom of the page.

Essentially, the workflow is trying to pass the form initialization data - and if that initialization data does conform to the form's schema the form gives up. This occurs even if you are not trying to pass any initialization data to the form. Having to pass an empty xml graph is inconvenient and annoying, but unfortunately that's the way it works.

So, how do you do this

1) You extract your infopath schema (you are using infopath ) by using "Save As Source Files", 2) Run xsd.exe on the schema to generate a serializable clas.
(C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin) using xsd.exe.  Just type xsd.exe at the command prompt and it will give you all of the options - you will want xsd.exe /c [path to schema]\[schema name].xsd /o:[destination directory].
3) Add generated class to your project
4) In your OnWorkflowActivated Invoked method set the value of the context data variable.  For example if your generated class is called ModificationForm and you don't have any data to initialize the form with:
this.updateTasksContextData = this.SerializeModificationData(new ModificationForm());

If you have the Enterprise Content Management Starter kit you can see this in situ in the ModificationSample project, but you only really see the equivalent of step 4.





Re: SharePoint - Workflow Modifying Approvers

Amit V

You are right Mark. I was not passing the right data to initialization form.

Thanks for your help.

Best Regards