3

Why doesn't the ItemAdded Receiver get called when a task was created by a workflow, but when a user created a task it does? I tried setting the Receivers ListUrl to my list URL and tried using the list template id 107. In both ways only a manual added item will call the item added receiver.

Edit:

What I try to accomplish is the following: whenever a task is added to the global task list, i try to get the due date of that task and update an item in an other list with that value. The problem here is that task items which are created by workflows do not seem to trigger my ItemAdded Receiver.

  • I'm nearly certain I have done this in the past and it worked fine. Have you tried checking your ULS logs to see if any errors are being returned? You could also try attaching the Visual Studio debugger and setting breakpoints to see is your event receiver being called and possibly failing. – Steven Mulkerrins Sep 21 '15 at 16:35
1

If workflow run under system account token it will not call event receiver, you have to provide user's token for call event receiver, please refer below code would be help to you

SPUserToken userToken = null;
SPSecurity.RunWithElevatedPrivileges(delegate() {
    using(SPSite spsite = new SPSite(url)) {
        using(SPWeb spweb = spsite.OpenWeb()) {
            string user = "Login name of user having rights";
            userToken = spweb.Site.RootWeb.EnsureUser(user).UserToken;
        }
    }
});

//open web by users token

using(SPSite spsite = new SPSite(url, userToken)) {
    using(SPWeb spWeb = spsite.OpenWeb()) {
        SPList splist = spweb.Lists["MyLists"];
        SPListItem item = splist.items.Add();
        item["Title"] = "My Title";

        //here update list through provided users token so will call event reciever
        item.update()
    }
}
  • it's a sharepoint designer workflow without any impersonation steps so it runs as the user who started the workflow. also when i add items to the task list as system account, i still trigger the receiver – Razze Apr 7 '14 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.