aspx 内容类型 传值给workflow ontaskchanged 获取该值的问题(十万火急!!!)
1.新建了一个aspx的内容类型
<?xml version="1.0" encoding="utf-8"?><Elements Id="e6637d50-34da-4c49-9ffa-ec5f3dda3039" xmlns="http://schemas.microsoft.com/sharepoint/"> <ContentType ID="0x0108010023070ff5defd410a8bb9252cb244935b" Name="shouTask2" Group="Development" Description="Developing Content Type" Version="0"> <FieldRefs> <FieldRef ID="{f0530392-00ee-439c-afab-62a603d0db1c}" Name="wfida" /> <FieldRef ID="{e34302ce-6d8f-48d1-92a5-2daeb2be6aee}" Name="wfagree" /> </FieldRefs> <XmlDocuments> <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/events"> <Receivers /> </XmlDocument> <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url"> <FormUrls xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url"> <New>_layouts/shouTaskASPX/shouTask2.aspx</New> <Display>_layouts/shouTaskASPX/shouTask2.aspx</Display> <Edit>_layouts/shouTaskASPX/shouTask2.aspx</Edit> </FormUrls> </XmlDocument> </XmlDocuments> </ContentType> <Field ID="{f0530392-00ee-439c-afab-62a603d0db1c}" Type="Text" Name="wfida" DisplayName="工作流标识" StaticName="工作流标识" Hidden="FALSE" Required="FALSE" Sealed="FALSE" /> <Field ID="{e34302ce-6d8f-48d1-92a5-2daeb2be6aee}" Type="Text" Name="wfagree" DisplayName="是否同意" StaticName="是否同意" Hidden="FALSE" Required="FALSE" Sealed="FALSE" /> </Elements>
protected void Submit_Click(object sender, EventArgs e) { SPWeb web = SPContext.Current.Web; web.AllowUnsafeUpdates = true; SPListItem item = SPContext.Current.Item as SPListItem; Hashtable taskHash = new Hashtable(); taskHash["TaskStatus"] = "complete"; if (r1.Checked) taskHash["wfagree"] = "1"; else taskHash["wfagree"] = "0"; SPWorkflowTask.AlterTask(m_task, taskHash, true); SPUtility.Redirect(List.DefaultViewUrl, SPRedirectFlags.UseSource, HttpContext.Current); }
private void onTaskChanged2_Invoked(object sender, ExternalDataEventArgs e) { string temp = "asdfasdasdfasdf"; string agree = onTaskChanged2_AfterProperties1.ExtendedProperties["e34302ce-6d8f-48d1-92a5-2daeb2be6aee"].ToString(); agree = onTaskChanged2_AfterProperties1.ExtendedProperties["wfagree"].ToString(); if (agree == "1") { runtask = 3; } else { runtask = 2; } }
仔细对比一下wfagree的guid 确实是有这么一个属性的e34302ce-6d8f-48d1-92a5-2daeb2be6aee
并且值已经从aspx取到,且不为空。但是我用了两种方法
string agree = onTaskChanged2_AfterProperties1.ExtendedProperties["e34302ce-6d8f-48d1-92a5-2daeb2be6aee"].ToString(); agree = onTaskChanged2_AfterProperties1.ExtendedProperties["wfagree"].ToString();
private object GetExtendedProperty(SPWorkflowTaskProperties properties, string key) { // First try to get the value by hashtable key if (properties.ExtendedProperties.ContainsKey(key)) { // Key was found, so just return the value return properties.ExtendedProperties[key]; } else { // Key was not found in hashtable, so it may have been translated to the field's Guid Guid fieldId; // Try to get the Guid for the field, using "key" as the display name if (TryGetTaskListFieldId(key, out fieldId)) { // We got the field's id, now use that to retrieve the value (or null) from the hashtable return properties.ExtendedProperties[fieldId]; } else { // Field wasn't found either return null; } } } private bool TryGetTaskListFieldId(string displayName, out Guid fieldId) { if (workflowProperties.TaskList.Fields.ContainsField(displayName)) { fieldId = workflowProperties.TaskList.Fields[displayName].Id; return true; } else { fieldId = default(Guid); return false; } }