首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 企业软件 > 行业软件 >

aspx 内容类型 传值给workflow ontaskchanged 获取该值的有关问题(!)

2012-03-26 
aspx 内容类型 传值给workflow ontaskchanged 获取该值的问题(十万火急!!!)1.新建了一个aspx的内容类型XML

aspx 内容类型 传值给workflow ontaskchanged 获取该值的问题(十万火急!!!)
1.新建了一个aspx的内容类型 

XML code
<?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>


2.aspx后台代码如下:
C# code
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);        }


3.workflow后台代码如下:
C# code
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;            }        }


用vs2008调试进onTaskChanged2_Invoked 看onTaskChanged2_AfterProperties1
里面有个属性ExtendedProperties里确实有TaskStatus,但是没有 wfagree



仔细对比一下wfagree的guid 确实是有这么一个属性的e34302ce-6d8f-48d1-92a5-2daeb2be6aee
并且值已经从aspx取到,且不为空。但是我用了两种方法

C# code
string agree = onTaskChanged2_AfterProperties1.ExtendedProperties["e34302ce-6d8f-48d1-92a5-2daeb2be6aee"].ToString();            agree = onTaskChanged2_AfterProperties1.ExtendedProperties["wfagree"].ToString();

都说什么对象没有引用实例。

帮忙解决,谢谢

[解决办法]
在你的代码中加入下面的两个函数,然后用第一个函数取值。


C# code
        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;            }        } 

热点排行