Monthly Archives: March 2008

[SP Gotchas] Error When Programmatically Starting Workflow

I’ve recently had a need to model a looping workflow with a SharePoint Designer workflow.  Designer doesn’t have a ‘Start Workflow’ action available by default, so I installed the Useful SharePoint Designer Workflow Activities on Codeplex.

My workflow would be designed like this

  1. Collect Data From Users with Task Form
  2. Set Workflow Variable to Step 1 Task ID
  3. Check for repeat condition on Above Task
    1. Start a new instance of this workflow
  4. (Workflow Done)

Looks great, but when running this workflow, I kept getting the following error:

Exception from HRESULT: 0x8102009B

at Microsoft.SharePoint.Library.SPRequest.AddWorkflowToListItem(String bstrUrl, String bstrListName, Int32 lItemID, Int32 lItemLevel, Int32 lItemVersion, Guid workflowPackageId, Guid& pWorkflowInstanceId, Guid workflowTaskListId, String bstrStatusFieldInternalName, Int32 lAuthorId)

I searched around and found out that you cannot start an instance of a workflow on an item when the same workflow is already running on that item.  Lucy’s blog had a code sample which checked the target item for the duplicate WF and removed the WF if it was found.  I wanted to keep the data from the first workflow, and this would remove it.  Not exactly what I wanted.

Here’s a simpler approach I took:

Modify the original workflow (Workflow A)…

  1. Collect Data From Users with Task Form
  2. Set Workflow Variable to Step 1 Task ID
    1. Check for repeat condition on Above Task
    2. Start a new instance of the LookBack workflow
    3. Stop this workflow and log the message ‘Completed – Looping’
  3. (Workflow Done)

Create a second workflow called ‘LoopBack’:

  1. Pause for 1 minute
  2. Start a new instance of Workflow A
  3. (Workflow Done)

I can start an instance of LoopBack at the same time as Workflow A.  Then, LoopBack waits while Workflow A completes.  After that, it starts Workflow A over again.  The pause is there since Workflow A takes some time to fully complete.

Note, if you’re not running SP1, the Pause for 1 minute step will take 30 minutes to complete.  Installing SP1 will fix this issue.

This is a really simple way to model a looping workflow without going into Visual Studio.

[Quotes] Bradbury on Lives Effecting Change

Fahrenheit 451, by Ray Bradbury

Everyone must leave something behind when he dies, my grandfather said.  A child or a book or a painting or a house or a wall built or a pair of shoes made.  Or a garden planted.  Something your hand touched some way so your soul has somewhere to go when you die, and when people look at that tree or that flower you planted, you’re there.  It doesn’t matter what you do, he said, so long as you change something from the way it was before you touched it into something that’s like you after you take your hands away.  The difference between the man who just cuts lawns and a real gardener is in the touching, he said.  The lawn cutter might just as well not have been there at all; the gardener will be there a lifetime.

[Quotes] Wealth as a Curse?

Proverbs 30:8-9

Keep falsehood and lies far from me;
       give me neither poverty nor riches,
       but give me only my daily bread.

Otherwise, I may have too much and disown you
       and say, ‘Who is the LORD ?’
       Or I may become poor and steal,
       and so dishonor the name of my God.

SharePoint Content Deployment Job Stuck at ‘Preparing’

Not only did DST rob me of an hour of sleep this weekend, it’s also slowing down my content deployment jobs!  Thanks a lot, Benjamin Franklin!

This KB article seems to explain the problem as beeing that the OWSTIMER has its own clock which is separate from the system clock.  I scheduled a job for 11:17am this morning and it showed a status of ‘preparing’ until 12:17pm, at which time it ran smoothly.

A couple of solutions: set your jobs to run as if you were still in non-DST.  Right now, that would mean that I would schedule a job for one hour from now if I wanted it to run immediately.  Second solution: change your server time zone to a non-DST time zone and disable automatic time updates.

Update 2008-03-11:
Install SP1 to alleviate this problem!  I assumed the server I was working on had SP1, but I was wrong.  Running the update fixed the problem immediately.