Link Field for the Workflow Task List in SharePoint 2010
I noticed that the display name for the "Link" field for WorkflowTask content type has changed to "Related Content" with static name "WorkflowLink."
The Link field normally contains the Url to the List and the title/name of the item that the workflow task is referring to in a comma delimited format.
I was using the Link field to get the associated item information.
Excerpt from C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES\ctypes\ctypeswss.xml:
Excerpt from C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES\fields\fieldswss.xml:
I discovered that the core.resx file under 14/Template/Resources now defines LinkField as "Related Content" in SharePoint 2010. The SharePoint 2007 version of the resx file has it as just "Link". I had to change my code to account for the different display name for the Link field in SharePoint 2010 tasks lists.
public static string GetWorkflowLinkFieldName(SPListItem taskitem)
{
foreach (SPField field in taskitem.Fields)
{
if (field.StaticName == "WorkflowLink")
{
return field.Title;
}
}
return "Link";
}
I noticed by looking at the ContentType for Workflow Task that there is a WorkflowListId and WorkflowItemId field.
And after doing some testing, I became aware that instead of parsing out the Link / Related Content field, I could have just used the WorkflowListId and WorkflowItemId fields to get the associated Item, instead.
So rather than doing all that parsing, I could have just done something like this after validating the fields exist and are populated:
The Link field normally contains the Url to the List and the title/name of the item that the workflow task is referring to in a comma delimited format.
I was using the Link field to get the associated item information.
Excerpt from C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES\ctypes\ctypeswss.xml:
<ContentType Version="0" Group="_Hidden" Name="$Resources:WorkflowTask" ID="0x010801" Description="$Resources:WorkflowTaskCTDesc" Hidden="TRUE">
<FieldRefs>
<FieldRef Name="Link" ID="{58ddda52-c2a3-4650-9178-3bbc1f6e36da}"/>
<FieldRef Name="OffsiteParticipant" ID="{16b6952f-3ce6-45e0-8f4e-42dac6e12441}"/>
<FieldRef Name="OffsiteParticipantReason" ID="{4a799ba5-f449-4796-b43e-aa5186c3c414}"/>
<FieldRef Name="WorkflowOutcome" ID="{18e1c6fa-ae37-4102-890a-cfb0974ef494}"/>
<FieldRef Name="WorkflowName" ID="{e506d6ca-c2da-4164-b858-306f1c41c9ec}"/>
<FieldRef Name="GUID" ID="{ae069f25-3ac2-4256-b9c3-15dbc15da0e0}"/>
<FieldRef Name="TaskType" ID="{8d96aa48-9dff-46cf-8538-84c747ffa877}"/>
<FieldRef Name="FormURN" ID="{17ca3a22-fdfe-46eb-99b5-9646baed3f16}"/>
<FieldRef Name="FormData" ID="{78eae64a-f5f2-49af-b416-3247b76f46a1}"/>
<FieldRef Name="EmailBody" ID="{8cbb9252-1035-4156-9c35-f54e9056c65a}"/>
<FieldRef Name="HasCustomEmailBody" ID="{47f68c3b-8930-406f-bde2-4a8c669ee87c}"/>
<FieldRef Name="SendEmailNotification" ID="{cb2413f2-7de9-4afc-8587-1ca3f563f624}"/>
<FieldRef Name="PendingModTime" ID="{4d2444c2-0e97-476c-a2a3-e9e4a9c73009}"/>
<FieldRef Name="Completed" ID="{35363960-d998-4aad-b7e8-058dfe2c669e}"/>
<FieldRef Name="WorkflowListId" ID="{1bfee788-69b7-4765-b109-d4d9c31d1ac1}"/>
<FieldRef Name="WorkflowItemId" ID="{8e234c69-02b0-42d9-8046-d5f49bf0174f}"/>
<FieldRef Name="ExtendedProperties" ID="{1c5518e2-1e99-49fe-bfc6-1a8de3ba16e2}"/>
</FieldRefs>
</ContentType>
<FieldRefs>
<FieldRef Name="Link" ID="{58ddda52-c2a3-4650-9178-3bbc1f6e36da}"/>
<FieldRef Name="OffsiteParticipant" ID="{16b6952f-3ce6-45e0-8f4e-42dac6e12441}"/>
<FieldRef Name="OffsiteParticipantReason" ID="{4a799ba5-f449-4796-b43e-aa5186c3c414}"/>
<FieldRef Name="WorkflowOutcome" ID="{18e1c6fa-ae37-4102-890a-cfb0974ef494}"/>
<FieldRef Name="WorkflowName" ID="{e506d6ca-c2da-4164-b858-306f1c41c9ec}"/>
<FieldRef Name="GUID" ID="{ae069f25-3ac2-4256-b9c3-15dbc15da0e0}"/>
<FieldRef Name="TaskType" ID="{8d96aa48-9dff-46cf-8538-84c747ffa877}"/>
<FieldRef Name="FormURN" ID="{17ca3a22-fdfe-46eb-99b5-9646baed3f16}"/>
<FieldRef Name="FormData" ID="{78eae64a-f5f2-49af-b416-3247b76f46a1}"/>
<FieldRef Name="EmailBody" ID="{8cbb9252-1035-4156-9c35-f54e9056c65a}"/>
<FieldRef Name="HasCustomEmailBody" ID="{47f68c3b-8930-406f-bde2-4a8c669ee87c}"/>
<FieldRef Name="SendEmailNotification" ID="{cb2413f2-7de9-4afc-8587-1ca3f563f624}"/>
<FieldRef Name="PendingModTime" ID="{4d2444c2-0e97-476c-a2a3-e9e4a9c73009}"/>
<FieldRef Name="Completed" ID="{35363960-d998-4aad-b7e8-058dfe2c669e}"/>
<FieldRef Name="WorkflowListId" ID="{1bfee788-69b7-4765-b109-d4d9c31d1ac1}"/>
<FieldRef Name="WorkflowItemId" ID="{8e234c69-02b0-42d9-8046-d5f49bf0174f}"/>
<FieldRef Name="ExtendedProperties" ID="{1c5518e2-1e99-49fe-bfc6-1a8de3ba16e2}"/>
</FieldRefs>
</ContentType>
Excerpt from C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES\fields\fieldswss.xml:
<Field DisplayName="$Resources:core,LinkField;" ReadOnly="TRUE" Sealed="TRUE" Type="URL" Group="_Hidden" StaticName="WorkflowLink" SourceID="http://schemas.microsoft.com/sharepoint/v3" Name="WorkflowLink" ID="{58DDDA52-C2A3-4650-9178-3BBC1F6E36DA}"> </Field>
I discovered that the core.resx file under 14/Template/Resources now defines LinkField as "Related Content" in SharePoint 2010. The SharePoint 2007 version of the resx file has it as just "Link". I had to change my code to account for the different display name for the Link field in SharePoint 2010 tasks lists.
public static string GetWorkflowLinkFieldName(SPListItem taskitem)
{
foreach (SPField field in taskitem.Fields)
{
if (field.StaticName == "WorkflowLink")
{
return field.Title;
}
}
return "Link";
}
I noticed by looking at the ContentType for Workflow Task that there is a WorkflowListId and WorkflowItemId field.
And after doing some testing, I became aware that instead of parsing out the Link / Related Content field, I could have just used the WorkflowListId and WorkflowItemId fields to get the associated Item, instead.
So rather than doing all that parsing, I could have just done something like this after validating the fields exist and are populated:
Guid itemListGuid = new Guid(_TaskListItem["WorkflowListId"].ToString());
int itemID = int.Parse(_TaskListItem["WorkflowItemId"].ToString());
SPList itemList = _TaskListItem.Web.Lists[itemListGuid];
SPListItem item = itemList.GetItemById(itemID);
int itemID = int.Parse(_TaskListItem["WorkflowItemId"].ToString());
SPList itemList = _TaskListItem.Web.Lists[itemListGuid];
SPListItem item = itemList.GetItemById(itemID);
Comments
Post a Comment