R – Why does the SharePoint workflow fail when the client is running Vista or Windows 7

mosssharepointsharepoint-2007workflow

I have a similar situation to this question.

I have a custom sequential SharePoint workflow, deleoped in Visual Studio 2008. It is associated with an InfoPath form submitted to a form library. It is configured to automatically start when an item is created.

It works sometimes. Sometimes it just fails to start.

Just like the question linked above, I checked in the debugger, and the issue is that the InfoPath fields published as columns in the library are empty when the workflow fires. (I access the fields with workflowProperties.Item["fieldName"].) But there appears to be a race condition, as those fields actually show up in the library view, and if I terminate the failed workflow and restart it manually, it works fine!

After a lot of head-scratching and testing, I've determined that the workflow will start successfully if the user is running any version of IE on Windows XP, but it fails if the same user submits the same form data from a Vista or Windows 7 client machine.

Does anyone have any idea why this is happening?

Best Answer

I have used another solution which will only wait until InfoPath property is available (or max 60 seconds):

public SPWorkflowActivationProperties workflowProperties =
   new SPWorkflowActivationProperties();

private void onOrderFormWorkflowActivated_Invoked(object sender, ExternalDataEventArgs e)
{
   SPListItem workflowItem;
   workflowItem = workflowProperties.List.GetItemById(workflowProperties.ItemId);

   int waited = 0;
   int maxWait = 60000; // Max wait time in ms
   while (workflowItem["fieldName"] == null && (waited < maxWait))
   {
      System.Threading.Thread.Sleep(1);
      waited ++;
      workflowItem = workflowProperties.List.GetItemById(workflowProperties.ItemId);
   }

   // For testing: Write delay time in Workflow History Event
   SPWorkflow.CreateHistoryEvent(
      workflowProperties.Web,
      workflowProperties.WorkflowId, 
      (int)SPWorkflowHistoryEventType.WorkflowComment,
      workflowProperties.OriginatorUser, TimeSpan.Zero, 
      waited.ToString() + " ms", "Waiting time", "");
}

workflowProperties.Item will never get the InfoPath property in the code above. workflowProperties.List.GetItemById(workflowProperties.ItemId) will after some delay.

Related Topic