spweb.getListItem在自定义工作流活动中返回null
-
16-10-2019 - |
题
我使用以下代码创建了一个自定义工作流活动:
namespace Custom.SharePoint
{
public class CustomActivity : Activity
{
#region Fields
public static readonly DependencyProperty __ContextProperty =
DependencyProperty.Register("__Context", typeof(WorkflowContext), typeof(WebServiceActivity));
public static readonly DependencyProperty AddressProperty =
DependencyProperty.Register("Address", typeof(string), typeof(WebServiceActivity));
public static readonly DependencyProperty StatusIdProperty =
DependencyProperty.Register("StatusId", typeof(string), typeof(WebServiceActivity));
#endregion
#region Properties
public WorkflowContext __Context
{
get { return (WorkflowContext)GetValue(__ContextProperty); }
set { SetValue(__ContextProperty, value); }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[Browsable(true)]
public string Address
{
get { return (string)GetValue(AddressProperty); }
set { SetValue(AddressProperty, value); }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[Browsable(true)]
public string StatusId
{
get { return (string)GetValue(StatusIdProperty); }
set { SetValue(StatusIdProperty, value); }
}
#endregion
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
var listItem = this.__Context.Web.GetListItem(this.__Context.CurrentItemUrl);
var requestId = listItem["RequestId"];
// rest of code removed for brevity
});
return ActivityExecutionStatus.Closed;
}
}
}
很遗憾, this.__Context.Web.GetListItem(this.__Context.CurrentItemUrl)
即使 this.__Context.CurrentItemUrl
具有有效的值(例如“ http:// {服务器名称}/lists/{list name}/dispform.aspx?id=9”)
难道我做错了什么?
解决方案
我从来没有使用过spweb.getListItem的运气...过去,我在处理WorkFlowContext对象时使用了以下内容:
SPListItem item = __Context.Web.Lists[new Guid(__Context.ListId)].GetItemById(__Context.ItemId);
应该做到这一点。