Udostępnij za pośrednictwem


How To: Work around OnTaskCreated activity to get TaskId

Behavior/Symptoms:

  • OnTaskCreated activity was used to get taskid after executing createtask activity to send emails from sendmail activity along with task id, instead of sending an email using sendemailnotification=true from createtask activity.
  • sendemailnotification=true wasn't working for some reasons though timer was running fine.
  • After implementing OnTaskCreated activity at all places, WF gets locked at OnTaskCreated activity and resumes after 15-20 min.

Workaround:

  1. Remove the OnTaskCreated activity.
  2. Right click CreateTask activity, go to ListItemId property. Click on that field, It will open up the binding box. Select the second tab “Bind to a new member”, in that, provide the member name & below that select the “Create Field” option. Save & close.
  3. Drag & drop one CodeActivity after the CreateTask activity on your WF.
  4. Now in CodeActivity, you can access that field value which you defined in second step, that will contain the new TaskId which you want, to complete your functionality.

Comments

  • Anonymous
    June 21, 2012
    Yeeee. Great solution. The OnTaskCreated works in the OWSTIMER context which is piloted by the WorkFlow Timer Job. This timer job is by default scheduled every 5 minutes. With your solution, all code runs in the W3WP context and than you can expect on the continuity of events, without annoying gap. thank you very much, Sergio http://zsvipullo.blogspot.it/

  • Anonymous
    July 11, 2012
    Thanks a ton! You saved me many an hour of misery!

  • Anonymous
    February 17, 2013
    Hi, I am trying to get users to task list when task is created. When I used listitemId to update the task list item, its throwing an exception stating  "Item does not exist. It may have been deleted by other user." I would be glad if you can help me how to work around. Thank you.

  • Anonymous
    July 05, 2013
    Thank you, that really helped me out.

  • Anonymous
    August 04, 2013
    Hi, Now I am able to get the Id , But while I am executing my code I am facing a following error " Value doesnot fall within the expected range"(Arguement exception) Sample code I used        public Int32 createTaskLIClearence_ListItemId1 = default(System.Int32);        private void codeActivity1_ExecuteCode(object sender, EventArgs e)         {             SPListItem spLstItem = workflowProperties.TaskList.Items.GetItemById(this.createTaskLIClearence_ListItemId1);              SPFieldUserValueCollection spUservalues = Utility.ConvertSPUserCollection("President", workflowProperties.Web);            spLstItem[SPBuiltInFieldId.AssignedTo] = spUservalues.ToString();             spLstItem[SPBuiltInFieldId.WorkflowVersion] = 1;             spLstItem.Update();         } Please guide me Thanks in advance, Regards, sathya

  • Anonymous
    November 19, 2013
    If you get the exception "Item does not exist...", then I think you are using an old reference to the Web or List object. Try using this code instead to get the list item: SPWeb thisWeb = new SPSite(workflowProperties.SiteId).OpenWeb(workflowProperties.WebId); SPListItem thisItem = thisWeb.Lists[workflowProperties.TaskListId].GetItemById(workflowProperties.ItemId);

  • Anonymous
    March 26, 2014
    Hi, I am trying to get users to task list when task is created. When I used listitemId to update the task list item, its throwing an exception stating  "Item does not exist. It may have been deleted by other user." I would be glad if you can help me how to work around. Thank you.

  • Anonymous
    May 12, 2014
    Hi , I have the same scenario. But we are creating the tasks in Task list for every quarter through powershell. What if i want to fetch the Task id in this kind of scenario. Any help is greatly appreciated