Can't start a 2013 Workflow in an Event Receiver
I am trying to run a SP2013 workflow from an Event Receiver but I get the error "The request was aborted: The request was canceled. Client ActivityId: aec2fc1b-3f33-44d8-85ab-c6c976617b8c" at the point I actually attempt to start the Workflow.
The scenario is as follows. I have 2 lists: List A and List B. Users have permissions to create items in List A but not List B. When users create a new item in List A, a SP2013 workflow runs which then creates a new item in List B. List B should then
run another SP2103 Workflow but because of how SP and workflows work, this second workflow on List B doesn't automatically run. Thus I have created an Item Added Event Receiver on List B that will run the required workflow automatically (at least it should
if it worked!)
I'm sure the problem must be something to do with permissions but nothing I try seems to solve it:
I can't just use the account of the user triggering the event as this user will be the person adding items to List A and they don't have permissions to do anything in List B (thus they cannot see items in list B or start workflows)
I can't run using RunWithElevatedPrivileges as a) I don't think this works well with Event Receivers and b) SP2103 workflows cannot be run using the admin account.
I have tried impersonation with an account specifically set up for running workflows (named mydomain\wssworkflow). This account has full control of the entire site, lists etc. but it still gives the error mentioned above. My code is shown below - the error
occurs on the line:
wfi.StartWorkflowOnListItem(sub, properties.ListItemId, payload);
Any help in working out why this isn't working would be appreciated.
Thank you,
-Stephen
public override void ItemAdded(SPItemEventProperties properties)
base.ItemAdded(properties);
var wsm = new Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager(properties.Web);
var wfss = wsm.GetWorkflowSubscriptionService();
var subs = wfss.EnumerateSubscriptionsByList(properties.ListId);
foreach (var sub in subs)
if (sub.Name == "RequestAddedToListB")
var userToken = properties.Web.EnsureUser(@"mydomain\wssworkflow").UserToken;
using (SPSite site = new SPSite(properties.Site.ID, userToken))
using (SPWeb web = site.OpenWeb())
var payload = new Dictionary<string, object>();
payload.Add("itemId", properties.ListItemId);
payload.Add("WorkflowStart", "StartWorkflow");
var wfi = wsm.GetWorkflowInstanceService();
wfi.StartWorkflowOnListItem(sub, properties.ListItemId, payload);
break;
This is the alternate code I had using SPSecurity.RunWithElevatedPrivileges that didn't work. It gives the error
"Attempted to perform an unauthorized operation"
on the line
var subs = wfss.EnumerateSubscriptionsByList(properties.ListId);
Thank you.
public override void ItemAdded(SPItemEventProperties properties)
base.ItemAdded(properties); SPSecurity.RunWithElevatedPrivileges(delegate
var wsm = new Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager(properties.Web);
var wfss = wsm.GetWorkflowSubscriptionService();
var subs = wfss.EnumerateSubscriptionsByList(properties.ListId);
foreach (var sub in subs)
if (sub.Name == "RequestAdded")
using (SPSite site = new SPSite(properties.Site.ID))
using (SPWeb web = site.OpenWeb())
var payload = new Dictionary<string, object>();
payload.Add("itemId", properties.ListItemId);
payload.Add("WorkflowStart", "StartWorkflow");
var wfi = wsm.GetWorkflowInstanceService();
wfi.StartWorkflowOnListItem(sub, properties.ListItemId, payload);
break;
Similar Messages
-
Want to fire event receiver before workflow is execute while adding File in Document Library.
Hi,
I have Event receiver and workflow attached to same Document
Library.
Is it possible to fire event receiver before Workflow is
executed ?
Regards,
MilindHi,
According to your description, my understanding is that you want fire event receiver before workflow is excuted.
If the workflow for a list is set to auto-start, it will always execute before event receiver by default.
Here is a similar thread for your reference:
http://sharepoint.stackexchange.com/questions/3147/execution-order-of-event-receivers-and-workflow-on-a-list
As a workaround, you can set the workflow start by manually. Then , after executing the event receiver, you can start workflow using code at the end of event receiver.
Here is a demo for your reference:
http://zimmergren.net/technical/starting-a-sharepoint-workflow-from-code-event-receiver
More information about start workflow using C#:
http://jainnitin2411.wordpress.com/2012/07/06/programmaticallystartsharepointworkflow/
Best regards,
Zhengyu Guo
Zhengyu Guo
TechNet Community Support -
Can not start workflow from Servr OM code
Hello all ,
i want to start sharepoint 2013 workflow when a list item is updated based on some condition.
i have writen bellow code
var workflowServiceManager = new WorkflowServicesManager(web);
var workflowSubscriptionService = workflowServiceManager.GetWorkflowSubscriptionService();
//get all workflows associated with the list
//get lsit
SPList list = web.Lists["Leave"];
if (list != null)
var subscriptions = workflowSubscriptionService.EnumerateSubscriptionsByList(list.ID);
//run all workflows associated with the list
SPListItem item = list.GetItemById(Convert.ToInt32(drpRequest.SelectedValue));
foreach (var workflowSubscription in subscriptions)
//initiation parameters
var inputParameters = new Dictionary<string, object>();
//inputParameters.Add("List", leaveList.ID);
workflowServiceManager.GetWorkflowInstanceService().StartWorkflowOnListItem(workflowSubscription, item.ID, inputParameters);
on the last line it throws unauthorised access exception .
while current user have owner permissions.
here is error .
i have run full profile sync and user is availiable in UPS.
Please Help
MukeshHello all,
After running full profile sync i am able to deploy workflow.
it is running
but how can i elevate privilege to start workflow.
from code
Mukesh -
How to start a workflow by an event
Did somebody know how to start an OWB workflow after an event occur ?
In my application, the OWB workflow must start (and import data) after a record is insert in one of my application database table. Actually, I schedule a job to look in that table every single minute. The problem is that every minute, a connection is open and close on the application database. Also, the user have to wait for one minute (at most) before is job begin to be process. Can someone have a way to start OWB on event by using trigger, queue or something else ?
Thank you,
MBowf(your_OWF).wf_engine.LaunchProcess(item_type, item_key, process_name);
If your process is defined as:
Module: PRC_MODULE
Process_flow_package: PRC_PACK
Process_name: PROCESS
then ITEM_TYPE is PRC_PACK,
ITEM_KEY can be anything, like p_process_name||'_'|| SYSDATE to make sure it does not get doubled,
and process_name is PROCESS.
So when you call this function it would look like this:
owf(your_OWF).wf_engine.LaunchProcess('PRC_PACK', 'PROCESS_24072009120000', 'PROCESS'); -
Creating a custom workflow that copies events in a calendar to another one
Hello,
I was looking for a
Calendar displayed in having some
items from B to A.
calendar
So, I suppose That I
can run a workflow That
Automatically copies specific events
calendar and paste it in
B.
This is the step-by step
of the procedure I executed:
First, I checked That
Both calendars have exactly
the same columns.
Then I added an yes
/ no column in A Calendar
called "Rollup".
Since I'm a new SPD in the
whole world, I Decided
to use the 2010 plattform,
beacuse in the 2013 version
I couldnt find the "Copy
Item" Action.
I developed a list workflow
attached to Calendar A That Says:
Condition: If Current List:
Rollup equals Yes
Action: Copy Item to
Current Public Calendar
For an unknown reason, This
workflow always displays an error, Therefore
Accomplished never its purpose.
Does anyone have an idea what I
am doing acerca wrong?
Or knows a better workaround
for syncing two calendars?
Thanks for the help !Hi Corina,
For achieving your demand, you can create a SharePoint 2013 Workflow for Calendar01 as below and it works fine in my test:
Best Regards,
Eric
Eric Tao
TechNet Community Support -
Sharepoint 2013 ItemAdded event receiver for renaming files is not working
In SP 2013 I coded an event receiver that intercepts the ItemAdded event and it just renames the file.
It is a synchronous event (I added <Synchronization>Synchronous</Synchronization> in the Elements.xml).
This is the code:
public override void ItemAdded(SPItemEventProperties properties)
SPSecurity.RunWithElevatedPrivileges(delegate()
try
OutputDebugStringA("Inside ItemAdded");
string szHttpUrl = properties.WebUrl + "/" + properties.AfterUrl;
SPWeb openedWeb = properties.Web.Site.OpenWeb(properties.Web.ID);
SPFile spf = openedWeb.GetFile(szHttpUrl);
EventFiringEnabled = false;
string szUrl = properties.AfterUrl;
szUrl = szUrl + ".renamed";
string szNewFileName;
if (szUrl.LastIndexOf('\\') != -1) szNewFileName = szUrl.Substring(szUrl.LastIndexOf('\\') + 1);
else if (szUrl.LastIndexOf('/') != -1) szNewFileName = szUrl.Substring(szUrl.LastIndexOf('/') + 1);
else szNewFileName = szUrl;
if (properties.ListItem != null)
properties.ListItem["Title"] = szNewFileName;
properties.ListItem.Update();
spf.MoveTo(szUrl);
EventFiringEnabled = true;
base.ItemAdded(properties);
OutputDebugStringA("Renaming to " + szUrl);
catch (System.Exception exception)
OutputDebugStringA("ItemAdded ERROR: " + exception.ToString());
The problem is that when I upload a .txt file using Internet Explorer, just after the renaming is done, IE says that something went wrong and when I inspect the log files I see:
SPRequest.GetFileAndFolderProperties: UserPrincipalName=i:0).w|s-1-5-21-4050800873-4278272723-3073177257-500, AppPrincipalName= ,bstrUrl=http://sp2013/sites/demo/subsite1 ,bstrStartUrl=Shared Documents/test2.txt ,ListDocsFlags=16400 ,bThrowException=True 0fa7689c-674b-5045-c3a2-b214a5d4cbed
01/09/2014 15:29:26.75 w3wp.exe (0x1544) 0x16F4 SharePoint Foundation
General ai1wu Medium System.IO.FileNotFoundException: <nativehr>0x80070002</nativehr><nativestack></nativestack>,
StackTrace: at Microsoft.SharePoint.SPWeb.GetFileOrFolderProperties(String strUrl, ListDocsFlags listDocsFlags, Boolean throwException, SPBasePermissions& permMask) at Microsoft.SharePoint.SPFile.PropertiesCore(Boolean
throwException) at Microsoft.SharePoint.SPFile.get_Length() at Microsoft.Office.RecordsManagement.PolicyFeatures.ApplicationPages.UploadPage.OnSubmit(Object o, EventArgs e) at Microsoft.Office.RecordsManagement.PolicyFeatures.ApplicationPages.UploadExPage.OnSubmit(Object
o, EventArgs e) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeSta... 0fa7689c-674b-5045-c3a2-b214a5d4cbed
...gesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequest(HttpContext context) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) at System.Web.HttpApplication.PipelineStepManager.ResumeSteps(Exception error) at System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext
context, AsyncCallback cb) at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr
rootedObjectsPointer, IntPtr nativeRequestContex... 0fa7689c-674b-5045-c3a2-b214a5d4cbed
...t, IntPtr moduleData, Int32 flags) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) at System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr
pHandler, RequestNotificationStatus& notificationStatus) at System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr pHandler, RequestNotificationStatus& notificationStatus) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr
rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
0fa7689c-674b-5045-c3a2-b214a5d4cbed
So it is clear that the fact that I renamed the file is causing an issue in the SharePoint upload logic.
As a solution what I did was to not declare it as Synchronous, but if I do it then there is another error when Sharepoint shows the Edit Properties dialog... in this case the upload is OK but when it is time to show that Edit Property dialog IE fails and
says that the file has been already modified, or that "something went wrong".
If I use a synchronous event I get one problem. If I use the asynchronous event I get another problem... It's very frustating and I am pretty sure that a so important API like Event Receivers should have support renaming files so I hope someone can tell
me what I am doing wrong.
Thanks in advanceMay be you want to consider using the following code and see if it works for you.
http://social.msdn.microsoft.com/Forums/sharepoint/en-US/40c78e03-2dca-4083-89d2-a7430099da68/how-do-i-change-the-name-property-of-a-file-in-a-document-library?forum=sharepointdevelopment
Amit -
In Sharepoint 2013 Workflows, can a task be re-assigned?
I find that in SharePoint 2013 SP Designer based workflows, I can not find the settings to make the workflow tasks re-assignable.
This was possible in 2010, I can't find how or where to check off 're-assign task'.
Thanks, Roy KimHi,
In SharePoint 2013 there two platform workflows, SharePoint 2010 workflow and SharePoint 2013 workflow. Which kind of workflow
do you want to create? If it’s 2010 based workflow, then to reassign task form is used the same method. If it’s 2013, then there only two task actions, assign a task and start a task process, these two actions can’t set to reassign the task form.
Best Regards.
Kelly Chen
TechNet Community Support -
Sharepoint 2013 workflow does not start when item is created by another workflow
Hi I am having the next problem, I have a workflow on list B that starts when a new item is created. If I created the item manually the workflow works. Now I have a list A that has a workflow that creates a new item in List B. The problem is that when
de workflow in list A creates the list item in list B the workflow does not start.
I've used an account that is collection owner, an account that only has contribute permision and nothing works.
Any ideas?
0down
votefavorite
Hi I am having the next problem, I have a workflow on list B that starts when a new item is created. If I created the item manually the workflow works. Now I have a list A that has a workflow that creates a new item in List B. The problem is that when de workflow
in list A creates the list item in list B the workflow does not start.
I've used an account that is collection owner, an account that only has contribute permision and nothing works.
Any ideas?
0down
votefavorite
Hi I am having the next problem, I have a workflow on list B that starts when a new item is created. If I created the item manually the workflow works. Now I have a list A that has a workflow that
creates a new item in List B. The problem is that when de workflow in list A creates the list item in list B the workflow does not start.
I've used an account that is collection owner, an account that only has contribute permision and nothing works.
Any ideas?Hi Courfeyrak,
Here is another similar post with a workaround, you can try using the event receiver on listB item to start the workflow, when the listB item is created or updated by the workflow associated with listA.
http://social.technet.microsoft.com/Forums/sharepoint/en-US/19f71e38-7c04-430e-aa6b-764cbbf18c1c/2013-workflow-does-not-start-on-item-created-by-a-different-worklow?forum=sharepointcustomization
Thanks,
Daniel Yang
Forum Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
[email protected]
Daniel Yang
TechNet Community Support -
Enumerating and Starting SP-2013 Designer Workflows Programmatically
Hello,
I'm currently working with Office-365 Site-collections. I have a requirement of developing a
Sandbox Solution for Enumerating and Starting
all Designer Workflows Associated to a Given List. The list contains workflows of both SP-2010 and SP-2013 templates. They have to be started programmatically on select Items on a Button Click event.
I have tried using the property - SPList.WorkflowAssociations,
but the collection of WorkflowAssociations returned by this property consists of SP-2010 workflows only. The ones of SP-2013 are not listed.
I went through online blogs that suggested to use the APIs of 'Microsoft.SharePoint.WorkflowServicesBase.dll' (WorkflowServicesManager,
WorkflowSubscriptionService, etc..), in order to enumerate SP-2013 Workflows as well.
I'm not able to find the Api-package that installs the dll to GAC. Morever, I'm not sure if the APIs from this DLL can be used
in Sandbox Solutions. (I have installed SP-2013 SDK as well as
Workflow Manager package, but the above DLL is not found anywhere in my Dev-box).
It would be helpful if I get appropriate guidance on which APIs to use in Sandbox Solution for the above requirement.
Thanks
Abhijith R ShastryHi,
According to your post, my understanding is that you wanted to start workflow using Sandbox solution.
It is not supported to use the “Microsoft.SharePoint.WorkflowServicesBase.dll” API in sandbox solution(office 365/SharePoint online).
Also, it is not a good recommend to use the sandbox solution in SharePoint 2013 or SharePoint online.
As a workaround, we can use the Client Object Model to achieve the same scenario.
http://www.vrdmn.com/2014/05/managing-sharepoint-2013-workflows-with.html
http://www.codeproject.com/Articles/607127/Using-SharePoint-Workflow-Services-JS-API
What’s more, you also use the SharePoint APP to achieve it.
http://sharepoint.stackexchange.com/questions/87015/solved-start-a-workflow-of-the-host-web-via-sharepoint-app-and-jsom
Thanks & Regards,
Jason
Jason Guo
TechNet Community Support -
Can fill-able forms created in Acrobat 9 work with SharePoint 2013 workflow?
Okay so here's the deal.....
I have a few HR forms that need to be searchable and created as workflows in SharePoint 2013. Creating a custom list will not work because it is not a built to create forms. Integrating InfoPath would be ideal, but it will not work either because the company
will not pay for Enterprise licensing.
So my question is....what if I created a fill-able form in Acrobat and uploaded to SharePoint. Can I create a workflow from the document. The only question is, when the user fill out the form, where it will go? There is no submit button.
I guess the REAL question is, other than InfoPath, is there a work around to having forms on SharePoint that can be created as a workflow and made searchable. Did I mention that the forms must be fill-able.
Hope I make sense.
artisticwebNo, you cannot submit form values of a acrobat to SharePoint. You can use list form for basic form, else try using jquery to build custom forms as an alternative for infopath. Refer to the following codeplex solution. You could use this or build one similar
to that using the source code.
http://forms7.codeplex.com/
--Cheers -
Hi there,
1. Can we migrate SharePoint Designer 2013 workflows from DEV to UAT to Live without any issues? Any bad experiences?
2. When we deploy these workflows - does IIS need a restart?
Thank you.That depends, did you create reusable workflows? Those can be deployed to another environment (of course depending on dependencies within the workflow itself)
Kind regards,
Margriet Bruggeman
Lois & Clark IT Services
web site: http://www.loisandclark.eu
blog: http://www.sharepointdragons.com -
Any way i can create and manage SharePoint 2013 workflows in browser.
Guys,
is there any way i can created and manager sharepoint 2013 workflows in browser like Nintex lets you do. This will eliminate the need for sharepoint designer.
thanks
MMNo. SharePoint's work flows are created from SharePoint Designer or Visual Studio. Third party solutions like Nintex have other approaches.
Mike Smith TechTrainingNotes.blogspot.com
Books:
SharePoint 2007 2010 Customization for the Site Owner,
SharePoint 2010 Security for the Site Owner -
SharePoint 2013 workflow can not be completed
I use Visual studio 2013 to create an sharepoint 2013 workflow and just insert a single task into it. I fill the assignto property directly and the account does recieve the mail. Then I approve the created task but the workflow is still there and it can't
be completed after that. I have spend several days just try to make the workflow completed but I can't. Any clues?Hi Kevin,
As I know, there's two properties for task - one is Status with values 'In Progress', 'Completed' etc. Another property is 'Task outcome' with values 'approved' and 'rejected'. Task created by SignleTask, wait for task completion which means status field
should have value 'Completed' and then workflow will consider the task as complete. In your case I'm not sure if you have set the task status as completed or not. If you set the task status to completed only then workflow will consider the task as completed.
However, in your case you can set the property 'WaitForTaskCompletion' to false and just after SignleTask you can use other activity like - wait for item event or wait for field change, to find out if the task out field is 'approved' or 'rejected'. You can
put the activity in a loop and in the loop you can wait till due date or until the task-outcome is approved/rejected.
Thanks,
Sohel Rana
http://ranaictiu-technicalblog.blogspot.com -
Can SharePoint Apps and SharePoint 2013 workflow run on the same servers?
As the SharePoint 2013 workflow manager can run on non-sharePoint servers. Can I also use those server to host SharePoint apps in the Provider host model?
Or should I keep them separate?
This is a medium size deployment, 2 WFEs, 2 Apps, 1 Clustered DB. I would be adding 2 additional servers for hosting workflow manager, and SharePoint apps.
One other option I can think of would be to host the Workflow manager on the SharePoint Apps servers. And then host the SharePoint Apps on the 2 separate servers.
Any guidance or gatchas would be great the hear about.
Thanks!
Joshua FuenteYes, you should be able to run SharePoint Provider hosted apps using the Workflow Server as the provider. There is nothing in workflow manager that prevents running web sites on the same server.
Paul Stork SharePoint Server MVP
Principal Architect: Blue Chip Consulting Group
Blog: http://dontpapanic.com/blog
Twitter: Follow @pstork
Please remember to mark your question as "answered" if this solves your problem. -
Adding a ECB item menu action to a declarative Visual Studio 2013 Workflow
Hi
I have build a Sandbox 2013 workflow in Visual Studio which I can attach to my desired list. I want my users to be able to trigger this workflow via the item ECB menu as your can in an App Client Control. Is this easy to do say with a feature
- assuming you specify the list on workflow initiation.
Do I need to import my workflow into SPD 2013 and play around with Actions but that sounds a bit dodgy!
Regards
Daniel
Freelance consultantHi Daniel,
According to your post, my understanding is that you want to add ECB menu and start a
special workflow.
The following materials would be helpful:
Start a workflow with SharePoint (JavaScript)
https://gist.github.com/Aymkdn/3873181
Using ECMAScript Client Object Model from ECB Custom Actions
http://pholpar.wordpress.com/2011/04/08/using-ecmascript-client-object-model-from-ecb-custom-actions/
If I misunderstand what you mean, please provide more information about your requirement for further research.
Thanks,
Dennis Guo
TechNet Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
[email protected]
Dennis Guo
TechNet Community Support
Maybe you are looking for
-
How do I get rid of the menu on my TV after I set it up to play music and run photos. And then after about 5 minutes it shuts off the photos and goes to the info about the musician and song playing. I think this is getting too complicated for someone
-
Can a hacked website hack my iMac?
Hi, Yesterday I visited a website I've visited a number of times that appears to be run from India. However, when I went on yesterday instead of the usual homepage the page was black and had the words "HACKED BY PREDATOR" and then two boxes came up w
-
Which Depreciation Area is used to post values to G/L
Hi, I do understand that multiple depreciation area can be created and used in asset master at the same time to meet multiple requirements of the company. Lets say that we have two separate requirements of handling Depreciation of Vehicles. Book depr
-
V r using oracle xml db package to get the query result in xml format and then using the xalan in the java bean v r converting the xml result into xslt and then rendering it into the jsp pages. Now the question is, since we r performing the transform
-
Images suddenly appear distorted (streched).
Many of my photos in iphoto have suddenly become distorted (streched). I have now have the latest version og iphoto and have upgrated the library but the problem persists. Anyone have explanations or tips? only some are distorted per roll/event and s