WSS 3 SP2 OnTaskCreated

700 Views Asked by At

At work we had a problem after installing SP2 on WSS 3.0 related to an aleatory behavior of OnTaksCreated. For more info about this check "http://fightingvssharepoint.blogspot.com/2009/06/ontaskcreated-in-wss-30-sp2.html". We've not found the fix yet so we're trying an alternative solution. Consists in taking out OnTaksCreted and moving all its activities to OnTaskInit. If you do have the solution to the SP2 OnTaskCreated issue please let me know! But if you don't keep on reading please...

Custom workflow short brief: creates a new taks in the "Tasks" list, set the workflow status and sends an email to the "assignedTo" person. The email body is filled in with the recently created task information. In order to retrieve this info there's a call to the method "GetWorkflowTask". The method's signature is:

SPWorkflowTask task GetWorkflowTask (int taskID)

This method retrieves the task fine when called within OnTaskCreated. But if I call it within OnTaskInit, after the Createtask activity, retrieves null. Why?

Thanks! Jorge.

2

There are 2 best solutions below

2
On

I've seen this error before and unfortunately it's unpredictable, what I can give you is a workaround that works for me that involves specifying the listItemID (not the GUID) for the task you are asking SharePoint to create, from there you can access the list item on any future event assuming the create succeeded. If the list you use gets lots of traffic this might not work due to race conditions...

Once again "workaround" so be carful... -When you create your task "onTaskCreateTask1" specify the taskItemID explicity in the SPWorkflowTaskProperties.TaskItemID = x where x is a value you generate.
- store the generated taskItemID in a member variable - access the list using the getListItemFromID(x) method or using list.items[x] methods/accessors

I did not write the code below, give credit to Martin Holy.. http://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/26ff3ce1-6d6f-40a5-90b4-a7436acdfffe

/// <summary>
/// Because our task form's don't let us inject the ID we have to 
/// generate one beforehand.
/// </summary>
/// <param name="site"></param>
/// <param name="listId"></param>
/// <returns></returns>

public static int GetNextAvailableIdFromList(SPSite site, Guid listId)
{
    int nextAvailableID = -1;
    if (site.WebApplication.ContentDatabases.Count > 0)
    {
        string DBConnString = site.WebApplication.ContentDatabases[0].DatabaseConnectionString;
        SqlConnection con = new SqlConnection(DBConnString);
        try
        {
            con.Open();
            SqlCommand com = con.CreateCommand();
            com.CommandText = String.Format("select tp_NextAvailableId from AllLists where tp_ID = '{0}'", listId.ToString());

            nextAvailableID = (int)com.ExecuteScalar();
        }
        finally
        {
            con.Close();
        }
    }
    return nextAvailableID;
}
0
On

I had the same problem with OnTaskCreated, Microsoft is recommending that you not use OnTaskCreated, but to solve this see this blog post.