none
Start SharePoint Designer workflow from Event Receiver RRS feed

  • Question

  • I have a workflow that was built in sharpeoint designer that I need to kick off with an event receiver because of a limitation in SharePoint Online.  Testing in an on-pre dev environment, I've tried several variations of the code below.  Each time I debug this it doesn't find any associations and drops right through the foreach, I've tried this

    http://zimmergren.net/technical/starting-a-sharepoint-workflow-from-code-event-receiver

    as well with no luck.

    SPListItem addedItem = properties.ListItem;
            SPWorkflowManager manager = addedItem.ParentList.ParentWeb.Site.WorkflowManager;
            SPWorkflowAssociationCollection assoCollection = addedItem.ParentList.WorkflowAssociations;
           
            foreach (SPWorkflowAssociation asso in assoCollection)
            {
                manager.StartWorkflow(addedItem, asso, "");
            }
           
            base.ItemAdded(properties);

    I am 100% sure there is a workflow associated with this list, so I am very confused why the event handler can't see it.


    Tyler Bithell, Chief Technical Architect - Portals B2B Technologies LLC Atlanta GA SharePoint 2013 Blog http://sharepointv15.wordpress.com/ @B2B_Tech_TB


    • Edited by t_bithell Friday, June 21, 2013 8:12 PM
    Friday, June 21, 2013 8:11 PM

Answers

  • Hi,

    The dll exists in GAC (C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SharePoint.WorkflowServicesBase). I've referenced the dll in my project and it's working fine. Can you please check the error message in the ULS log file or event viewer when the code is not executing?


    Thanks,<br/> Sohel Rana<br/> <a href="http://ranaictiu-technicalblog.blogspot.com">http://ranaictiu-technicalblog.blogspot.com</a>

    Tuesday, June 25, 2013 1:34 AM

All replies

  • You have to make sure you event receiver is associated with the list,

    An event receiver would only fire if an event happens.  If your list is already populated and you attach an item event receiver to that list unless you manually go and update an item the event receiver code will never fire and should this be the case, it would be easier to set the workflow to run on new item created and item changed.

    So a kind of silly quick solution to start the workflow on all items would be to attach the workflow and make it start on new item created and item changed, then create test column in the list, open the list in datasheet view, populate the test column which then would fire off the workflow because the item changed, then delete the column.

    The full explanation is given on below thread

    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/bc155183-ffa2-420a-a653-6b7d6055216c/trigger-workflow-from-event-receiver


    Mark ANSWER if this reply resolves your query, If helpful then VOTE HELPFUL <hr> <b><a href="http://insqlserver.com">Everything about SQL Server | Experience inside SQL Server </a></b>-<a href="http://insqlserver.com">Mohammad Nizamuddin </a><br/>

    Saturday, June 22, 2013 2:58 AM
  • Is it SharePoint 2013 workflows? For SharePoint 2013 workflows, the above code will not work as it only find SharePoint 2010 workflow associations. For getting SharePoint 2013 workflow please follow the links:

    Programatically Access SharePoint 2013 Workflow

    Start SharePoint 2013 Workflow


    Thanks,
    Sohel Rana
    http://ranaictiu-technicalblog.blogspot.com


    • Edited by Sohel Rana Monday, June 24, 2013 12:55 AM Signature Update
    Monday, June 24, 2013 12:51 AM
  • Yes it is, but I can't find the dll I need in order to be able to use your code anywhere.

    Microsoft.SharePoint.WorkflowServices.dll

    Where should this be located?  Is there somewhere I could just download it from. Workflow manager is installed on the server, but this dll is nowhere on the computer. 


    Tyler Bithell, Chief Technical Architect - Portals B2B Technologies LLC Atlanta GA SharePoint 2013 Blog http://sharepointv15.wordpress.com/ @B2B_Tech_TB

    Monday, June 24, 2013 2:10 PM
  • Found the dll after a good bit of digging.  Turns out the "charm" search doesn't work as well as windows explorer.  Instead of solving my problem I have run into another one.  My even receiver won't run with code referencing WorkflowServicesManager.  When debugging it won't even stop on a break point within the even handler if there is any code that references it.  No error it just doesn't run.  I can deploy it to on-prem or cloud site, but it will not execute.  This is not the case with 2010 workflow code though.  Has anyone figured out a way around this or am I just SOL because MS decided they wouldn't allow this anymore? 

    Tyler Bithell, Chief Technical Architect - Portals B2B Technologies LLC Atlanta GA SharePoint 2013 Blog http://sharepointv15.wordpress.com/ @B2B_Tech_TB

    Monday, June 24, 2013 7:29 PM
  • Hi,

    The dll exists in GAC (C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SharePoint.WorkflowServicesBase). I've referenced the dll in my project and it's working fine. Can you please check the error message in the ULS log file or event viewer when the code is not executing?


    Thanks,<br/> Sohel Rana<br/> <a href="http://ranaictiu-technicalblog.blogspot.com">http://ranaictiu-technicalblog.blogspot.com</a>

    Tuesday, June 25, 2013 1:34 AM
  • This is not the answer to this question.  This answers a portion of a follow-up, but this doesn't at all answer how to execute a sharepoint 2013 workflow from an event receiver.  As best I can tell it is not possible.  When I switched over to the 2013 workflow code and debugged the event receiver would not even run.  I could watch it look like it would start and then the event receiver itself was bypassed completely.

    Tyler Bithell, Chief Technical Architect - Portals B2B Technologies LLC Atlanta GA SharePoint 2013 Blog http://sharepointv15.wordpress.com/ @B2B_Tech_TB

    Friday, June 28, 2013 4:27 PM
  • Hi,

    Please unmark the answer if the problem is not fixed. Also please check your ULS log for more error details. If your code is bypassed due to error, then there should be something in the windows event viewer or ULS log file. Can you please create a sample Visual Studio project (with event receiver and workflow start code) and share it to investigate the issue further?


    Thanks,
    Sohel Rana
    http://ranaictiu-technicalblog.blogspot.com>

    Sunday, June 30, 2013 5:15 AM