views:

647

answers:

3

I have custom approval state machibe workflow , this workflow attached to list and enabled to start when any item added or changed according to requirements, when my workflow reached publish state i write custom code to change it's Moderation status to Approved then workflow finished (item state will changed as i want ) but the problem that my workflow start as new instance again :( .

A: 

You have two options:

1) Keep the workflow as starting on added or changed and add activities to the start of the workflow which check the Moderation status and exit immediately if it is already approved.

2) Have the workflow start from code in an event receiver you write and check the item before starting it.

Thank you for your replay,first option is not possible because there's a case which approved item data changed and i need to start work flow againsecond option , not applicable because i want to enable user to assoiate my work flow to any listand i found some thing while debug my code ,when i pause my code some time after moderation status changed the workflow not started again .
mbakr
+1  A: 

If I understand your question you have a workflow that starts on add or change. But there are some circumstances where the item changes where you do not want the workflow to start. You cannot start the workflow in code because you need end users to add your workflow to lists themselves.

The only option then is to have the first activity in the workflow do checks to see if the workflow instance should be running. If not, exit the workflow instance. If you're building the workflow in SharePoint Designer and don't have such an activity you can build a custom activity for this in Visual Studio 2008 and then use that with SharePoint Designer. If you are building the whole workflow in Visual Studio 2008 then you can create a custom activity in Visual Studio to use with it.

Paul Andrew
thank you for your replay,But i want workflow to start on item changed but the problem of how i check for this case i update list item in workflow instance and this instance is complete , and immediatly found new instance to start again, how can i check for this case ,i use visual studio workflow
mbakr
A: 

i have Created small work around to fix this problem , i has created pre final state state which it redirect to final state directly , and i create Custom code activity in this state and make its code

Thread.Sleep(300);

and my problem fixed :)

Thanks God

Thanks Paul Andrew

mbakr