views:

961

answers:

1

I've found bit of a problem when running a workflow on a document library. When you click new document it'll open up microsoft word in this example. You write some stuff into the document then save it to the library. The workflow associated to the library, in this case a home grown approval workflow with start to run now that the list item has been created. The problem however is that the document is still open and thus checked out until the user closes word. If the first thing the workflow does is to set some of the other fields on this list item such as setting an approval status to "pending" then this will error. It errors because the document is checked out.

I've tried to get the workflow to wait for the document to be checked in but this is where I'm failing. I'm trying an OnWorkflowItemChanged activity and in the code of that checking that the change made was teh document being checked in, so after this I can then continue with the rest of my workflow. The problem is that this activity doesn't seem to pick up the check in event as a change. This kind of makes sense because closing the document which automatically checks it in doesn't actually change any of the item fields.

So I need to find some way inside of my workflow to detect the check in event, but until then wait where I am.

A: 

The fix to this is to have the workflow checkout the document, make any changes and then check it back in.

In code you would do this with a custom event handler. Check out the sharepoint SDK or MSDN for info on the object model.

In SharePoint Designer set your workflow to look like this:

Check "Automatically start this workflow when a new item is created" or "Automatically start this workflow when a new item is created" or select both options.

Hit next.

On the following page leave the conditions section blank.

In the action settings setup your workflow to look like this:

Check out item in <Current Item>
     then Wait for <Whatever fields you need to be set or actions you need>
     then Check in item in <Current Item> with comment: <Comment>

You can break this out into steps as well. For instance:

Step One - Check out current item
Step Two - Custom stuff you need to do
Step Three - Check in current item 
Junx