MAndrade

Hi, I must be missing something insanely simple when creating a custom email for my Approval Process Workflow. In my task's MethodInvoking function I'm building a custom email body, with a link to edit the Task for each user. I need the ID of the task for each user to be displayed in the email, but cannot seem to find it. Here's what I have now:

// Activity Handler for createTask1.MethodInvoking

// Initializes task creation properties

private void CreateTask(object sender, EventArgs e)

{

createTask_TaskId = Guid.NewGuid();

this.isTaskComplete = false; //set isTaskComplete bool to false to set up conditions for this task.

createTask_TaskProperties.Title = workflowProperties.TemplateName;

createTask_TaskProperties.AssignedTo = (string)this.taskReplicator.CurrentChildData[currentUser];

createTask_TaskProperties.Description = "Description." + description;

createTask_TaskProperties.HasCustomEmailBody = true;

string s = "";

s += "<HTML><HEAD>HEAD>";

s += "<BODY class=bodytext>";

s += "<TABLE class=mail dir=ltr cellSpacing=0>";

s += "<TBODY>";

s += "<TR class=header>";

s += "<TD class=header><SPAN class=175141502-27022007></SPAN><FONT face=Tahoma size=2>";

string[] n = workflowProperties.OriginatorUser.Name.Split(',');

s += n.GetValue(1).ToString() + " " + n.GetValue(0).ToString();

s += " has requested that you review ";

s += workflowProperties.Item.Name + "</FONT></TD></TR>";

s += "<TR class=body>";

s += "<TD class=body><SPAN class=175141502-27022007><FONT size=2><STRONG>";

s += this.description;

s += "</STRONG></FONT></SPAN></TD></TR>";

s += "<TR class=footer>";

s += "<TD class=footer>";

s += "<DIV><FONT size=2>To complete this task:</FONT></DIV>";

s += "<DIV>&nbsp;</DIV>";

s += "<DIV><STRONG>&nbsp;</STRONG>";

s += "<SPAN class=175141502-27022007>";

s += "<A href=";

s += workflowProperties.WebUrl + "/";

s += "/_layouts/TaskWFCT.aspx ID=";

s += createTask_TaskProperties.TaskItemId;

s += "&Name=";

s += createTask_TaskProperties.AssignedTo;

s += "&Source=";

s += workflowProperties.WebUrl;

s += "/_layouts/WrkStat.aspx";

s += "&List=";

s += workflowProperties.TaskListId.ToString();

s += "><FONT size=2><STRONG>Click here</STRONG></FONT></A>";

s += "<FONT size=2> to review ";

s += workflowProperties.Item.Name;

s += " and approve with optional comments.</FONT>";

s += "</SPAN>";

s += "<BR></DIV></TD></TR></TBODY></TABLE></BODY></HTML>";

createTask_TaskProperties.EmailBody = s;

currentUser++; //increment currentUser so that we know the index of the next task to be created.

}

I've bolded the area that doesn't work right. I cannot find the task id that you would see when looking in Sharepoint, and clicking on the workflow for the document that has started to look at it or edit it (ID of the Task Item for that one user assigned). Can anyone help Any info would be so greatly appreciated (I'm losing it trying to find this. :/ )



Re: SharePoint - Workflow Retrieving TaskId for custom email in MethodInvoking function

Nick Cox

I had the same problem. It's because Sharepoint doesn't actually create the task until the workflow is dehydrated - so the TaskItemId isn't known until that time.

If you add an OnTaskCreated activity after the CreateTask activity you'll be able to grab the TaskItemId from OnTaskCreated.AfterProperties.TaskItemId.
Of course, by then it's a bit late to alter the EmailBody of the task. I ended up giving up on the automated task notifications and just used the out of the box SendEmail activity instead.




Re: SharePoint - Workflow Retrieving TaskId for custom email in MethodInvoking function

MAndrade

Thanks so much! That was enough to make my head spin, thanks for giving it a bit of hope, I will try that.





Re: SharePoint - Workflow Retrieving TaskId for custom email in MethodInvoking function

Ian Fleming

Hi,

As per your suggestion I too tried with OnTaskCreated but unfortunately it does not working everytime.

i.e. Its not getting fired and the workflow exits after executing CreateTask.

Please advice me on how to go qbout as am breaking my haed for the last 3 days.

OS : Windows 2003 Server Ent Edition SP2

WSS 3.0 BETA 2

Thanks in advance






Re: SharePoint - Workflow Retrieving TaskId for custom email in MethodInvoking function

Andre Rentes

Hi,

I did this sugestion too, but the times working correctly, the times not working. I did a debug and put a breakpoint in OnTaskCreated but it create a task and not break onTaskCreated..

Do you solve this problem Ian Fleming And you Nock Cox, with you all working fine

I'm working with MOSS Enterprise / win2003 Standard

Thanks!






Re: SharePoint - Workflow Retrieving TaskId for custom email in MethodInvoking function

Nick Cox

Yeah, that's the approach I use all the time and I haven't had any problems with it. Does your OnTaskCreated activity have the correct correlation token and taskId properties set




Re: SharePoint - Workflow Retrieving TaskId for custom email in MethodInvoking function

Andre Rentes

Hi Nick, thanks for reply.

I verified my correlation token and it is ok. I found others posts about it. The OnTaskCreated doesn't fire.

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1698453&SiteID=1

But unfortunately nobody reply this problem yet.

If you discover something please share the solution

Thanks Nick






Re: SharePoint - Workflow Retrieving TaskId for custom email in MethodInvoking function

Ian Fleming

Hi,

Just delete the task type for this list then everything will get solved... i.e. goto List --> Settings --> Advance --> Delete 'task' content type... thats enough... Sometimes even after this you have the same error create a new list item and delete it before you start using the list...






Re: SharePoint - Workflow Retrieving TaskId for custom email in MethodInvoking function

Andre Rentes

Hi Fleming,

Thanks for reply, but I didn't understand what you wrote.

"Delete the task type" -> What is it Where I delete the task type

Please help-me again.

Thanks a lot

Att






Re: SharePoint - Workflow Retrieving TaskId for custom email in MethodInvoking function

Nick Cox

I've found that sometimes if there is an error in the workflow near the onTaskChanged activity it just silently fails rather than throwing an exception.

Have you tried stepping through your code in the debugger




Re: SharePoint - Workflow Retrieving TaskId for custom email in MethodInvoking function

Andre Rentes

Hi Nick

I tried stepping through my code in the debugger, but sometimes it not pass in OnTaskCreated, if I disable OnTaskCreated the workflow perfectly works.

My workflow is a state machine!

I don't know what to do Sad

Thanks for reply!






Re: SharePoint - Workflow Retrieving TaskId for custom email in MethodInvoking function

GeorgeChalkiadakis

I had the same problem taskitemid was taking value after the approval and i couldn¡¯t redirect the user correctly to the task editing form. I tried different approaches likes CallExternalMethod_CreateTask1.ListItemId.ToString() where CallExternalMethod_CreateTask1 is the instance name of createtask1 but it did not work . The solution i have found is the following . Please review it and if you have any suggestion post them back.

//open connect to SharePoint

SPWeb web = new SPSite(workflowProperties.SiteUrl).OpenWeb();
string fulltaskUrl;
try
{
//Use this to return the relevant URL's for use in e-mail of tasks.
string weburl = workflowProperties.WebUrl;
string taskUrl = "/_layouts/WrkTaskIP.aspx List=";

//Get the task list id
string listId = workflowProperties.TaskListId.ToString();
//initiate splist object of the task list
SPList list = web.Lists[workflowProperties.TaskListId];

int i = 0;
if (list.Items.Count > 0)
{

//Get the last item id and add 1 (SharePoint always add one 1 to the last id ) i have made many test with simultaneous

//users and it is working
i = list.Items[list.Items.Count - 1].ID + 1;
}
else
{
i = 1;
}
taskId = i.ToString();

web.Close();

fulltaskUrl = weburl + taskUrl + listId + "&ID=" + taskId;
}
catch (Exception ex)
{
web.Close();
fulltaskUrl = "";
}

return fulltaskUrl ;