Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Runing a SharePoint Designer Workflow from ItemAdded Event Receiver

$
0
0

Hi,

I have created a List Workflow in SharePoint Designer that changes permissions on the current List Item.

The List is a Document Library with a Document Set Content Type.

If I run the workflow manually it works, but I am trying to run it from my Event Receiver for the List so that I can check some properties and only run the Workflow on certain conditions.

There is only 1 Workflow associated with this List (Document Library) and I have manually created the Workflow in both my DEV and UAT environments, so they will both have a different Workflow Guid so I don't want to hard code the Guid into my code for obvious reasons.

My code that I've used to run the Workflow is below: (I've also tried it with elevated privileges, but still no luck.

SPWorkflowManager wfManager = properties.ListItem.ParentList.ParentWeb.Site.WorkflowManager;

                        SPWorkflowAssociationCollection wfAssociationCollection = properties.ListItem.ParentList.WorkflowAssociations;

                        SPWorkflowAssociation wfAssociation = wfAssociationCollection[0];

                        wfManager.StartWorkflow(properties.ListItem, wfAssociation, wfAssociation.AssociationData);

The Workflow code fires from my Event Receiver but it throws the error below.

Event ID: 6875

Error loading and running event receiver Test.Receivers.MyEventReceiver in Test.Receivers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31422c61d08d6776. Additional information is below.

:
   at Microsoft.SharePoint.Workflow.SPWinOeEngine.CreateWorkflow(Object context, SPWorkflowAssociation association, SPWorkflowEvent startEvent, Boolean bCreateOnly)
   at Microsoft.SharePoint.Workflow.SPWorkflowManager.StartWorkflowElev(Object context, SPWorkflowAssociation association, DateTime elevationTimeUtc, SPWorkflowEvent startEvent, SPWorkflowRunOptions runOptions)
   at Microsoft.SharePoint.Workflow.SPWorkflowManager.<>c__DisplayClass13.<StartWorkflow>b__12(SPSite superUserSite, SPWeb superUserWeb)
   at Microsoft.SharePoint.SPSecurity.<>c__DisplayClassc.<RunWithSystemSiteAndWeb>b__a()
   at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass4.<RunWithElevatedPrivileges>b__2()
   at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode)
   at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param)
   at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode)
   at Microsoft.SharePoint.Workflow.SPWorkflowManager.StartWorkflow(Object context, SPWorkflowAssociation association, SPWorkflowEvent startEvent, SPWorkflowRunOptions runOpts)
   at Microsoft.SharePoint.Workflow.SPWorkflowManager.StartWorkflow(Object context, SPWorkflowAssociation association, String eventData, SPWorkflowRunOptions runOptions)
   at Microsoft.SharePoint.Workflow.SPWorkflowManager.StartWorkflow(SPListItem item, SPWorkflowAssociation association, String eventData)
   at MyEventReceiver.<>c__DisplayClassa.<ItemAdded>b__8()
   at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass4.<RunWithElevatedPrivileges>b__2()
   at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode)
   at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param)
   at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode)
   at Test.Receivers.MyEventReceiver.ItemAdded(SPItemEventProperties properties)

Any help would be much appreciated.

Thanks,

Grant.


Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>