views:

269

answers:

2
A: 

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;
}
UJ
Never ran into this issue, but if this is the answer, that is a damn nasty workaround, wow. Not touching it with a 10ft pole :-D....
Colin
I agree 100%... total duct tape resolution
UJ
A: 

I have same problem with OnTaskCreated, Microsoft is recommending that you not use OnTaskCreated but to solve this issue I found this solution.

Hameds