none
SPD Workflow Does Not Start on SPListItem.Update

    Question

  • I've been doing a lot of searching and have found other people that have expressed the same problem, but I can't find any post that submits an actual answer.  I know I've accomplished the exact same on other SharePoint farms in the past, maybe I'm missing something obvious.

    I have a new MOSS 2007 farm, so it has SP2 installed.  I created a custom list and added a workflow using SPD to just send an email.  If I go through the browser and click New the workflow runs.  I created a simple web part that does the same thing (code below), the item is created in the list, but the workflow does not start and doesn't throw any error.  The code is not using elevated permissions so it isn't running as the system account (and the app pool is actually running as a service account we created).

    SPList list = SPContext.Current.Web.Site.RootWeb.Lists[listName];
    SPListItem item = list.Items.Add();
    item[listTitleFieldName] = "Message from x";
    item[listToFieldName] = txtTo.Text;
    item[listFromFieldName] = txtFrom.Text;
    item[listMessageFieldName] = txtBody.Text;
    item[listSentFromPageFieldName] = GetSentFromPage();
    item.Update();

     

    • Moved by Mike Walsh FIN Saturday, February 27, 2010 9:03 AM workflow questions go to the workflow forum (From:SharePoint - Development and Programming (pre-SharePoint 2010))
    Friday, February 26, 2010 9:27 PM

Answers

  • After digging around quite a bit it looks like this might be the type of solution that I'll have to attempt:

    http://vspug.com/jscott/2008/07/12/the-dreaded-server-out-of-memory-exception/ 

    Create a new user guest/visitor account
    Set up FBA
    Deploy an httpmodule to log in as the guest/visitor account

     
    Monday, March 01, 2010 11:16 PM

All replies

  • Thanks OlegO, but that's not the same problem as I've got.  Declarative workflows don't start under the system account after SP1.  You have to change the app pool account which we've done.  The workflow does start when the item is created through the browser, just not through a custom web part.  Both ways the item gets created and shows that it was created using the logged in person's account.
    Saturday, February 27, 2010 5:53 PM
  • Look a next link,
    http://social.msdn.microsoft.com/Forums/en-IE/sharepointworkflow/thread/7a690c4c-2ec8-4a81-8ce6-d2913f8fd760

    A quick solution is to trigger SharePoint Designer workflow programmatically , in my project I've added RunAssotiatedWF method and call RunAssotiatedWF after Update

    private static void RunAssotiatedWF(SPListItem listItem)
    {
                if (listItem == null)
                    throw new ArgumentNullException("listItem");
    
                // I could reproduce your issue, programmatically adding / updating a list item would not trigger the SharePoint Designer workflow.
                // http://social.msdn.microsoft.com/Forums/en-IE/sharepointworkflow/thread/7a690c4c-2ec8-4a81-8ce6-d2913f8fd760
                // http://blogs.msdn.com/sharepointdesigner/archive/2008/09/28/declarative-workflows-and-user-context.aspx
    
                // Issues that are fixed in Windows SharePoint Services 3.0
                // http://support.microsoft.com/kb/953749/
    
                // A declarative workflow does not start automatically after you install Windows SharePoint Services 3.0 Service Pack 1
                // http://support.microsoft.com/kb/947284
    
    
    			SPWorkflowManager objWorkflowManager = listItem.Web.Site.WorkflowManager;
    
    			if (objWorkflowManager.GetItemWorkflows(listItem).Count == 0)
    			{
    				SPWorkflowAssociationCollection objWorkflowAssociationCollection = listItem.ParentList.WorkflowAssociations;
    
    				foreach (SPWorkflowAssociation objWorkflowAssociation in objWorkflowAssociationCollection)
    				{
    					if (objWorkflowAssociation.AutoStartCreate || objWorkflowAssociation.AutoStartChange)
    					{
                            // System.Runtime.InteropServices.COMException (0x8102009B): 
                            //http://www.kindohm.com/archive/2007/06/26/com-exception-on-programmatic-wss-workflow-execution.aspx
    
                            //Failed on Start (retrying)
                            //http://msdn.microsoft.com/en-us/library/cc514224.aspx
    
    						SPWorkflow activeWorkflow = objWorkflowManager.StartWorkflow(listItem, objWorkflowAssociation, objWorkflowAssociation.AssociationData, true);
    					}
    				}
    			}
    }

    • Edited by OlegO. _ Monday, March 01, 2010 7:23 AM Fixed code markup
    Monday, March 01, 2010 7:09 AM
  • Thanks, I'll give this a shot and let you know!
    Monday, March 01, 2010 2:21 PM
  • So I tried the solution OlegO proposed and I got an error

    An error has occurred.Request for the permission of type 'Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' failed.

    So I dug back into the CAS (code access security) settings that were being deployed by VSEWSS1.3 and found an error.  I found that it was putting the wrong name for the dll into the custom CAS file because it named it MyAssembly.dll.dll.  I fixed that and then the workflow started trying to kick off with an error when it started.

    In the logs it alluded to the fact that several assemblies involved with Workflow and Security could not be called by partiallytrusted callers.  So I scrapped the the CAS permissions and deployed to the GAC.  That allowed the item to create and the workflow ran (without OlegO's code above or without running elevated permissions or impersonation)!  

    But of course I'm still not done yet, as this is for an internet site.  So when I hit the site anonymously the item creates, but the workflow doesn't start or cause an error.  I tried to impersonate a user, but that causes a login prompt.  If I elevate permissions to the system account it throws an error that says Server out of memory.  So I'm still stuck right now.
    Monday, March 01, 2010 11:01 PM
  • After digging around quite a bit it looks like this might be the type of solution that I'll have to attempt:

    http://vspug.com/jscott/2008/07/12/the-dreaded-server-out-of-memory-exception/ 

    Create a new user guest/visitor account
    Set up FBA
    Deploy an httpmodule to log in as the guest/visitor account

     
    Monday, March 01, 2010 11:16 PM