标签:c sharepoint
我正在尝试使用自定义工作流操作更新其他站点中的列表.这些网站位于同一网站集中.我已成功将自定义操作部署到SharePoint服务器.当我运行包含此操作的工作流时,工作流成功完成且没有错误.我确定该操作正在执行,因为我在工作流历史记录日志中看到包含service.LogToHistoryList()的行的结果,并且它们包含期望的值.问题是目标列表项实际上没有更新.下面是用于更新列表项的代码部分.
try
{
ISharePointService service = (ISharePointService)executionContext.GetService(typeof(ISharePointService));
service.LogToHistoryList(this.WorkflowInstanceId, SPWorkflowHistoryEventType.WorkflowComment, 0, TimeSpan.Zero, "Debugging Output", SiteUrl, string.Empty);
service.LogToHistoryList(this.WorkflowInstanceId, SPWorkflowHistoryEventType.WorkflowComment, 0, TimeSpan.Zero, "Debugging Output", List, string.Empty);
service.LogToHistoryList(this.WorkflowInstanceId, SPWorkflowHistoryEventType.WorkflowComment, 0, TimeSpan.Zero, "Debugging Output", Column, string.Empty);
service.LogToHistoryList(this.WorkflowInstanceId, SPWorkflowHistoryEventType.WorkflowComment, 0, TimeSpan.Zero, "Debugging Output", Value, string.Empty);
service.LogToHistoryList(this.WorkflowInstanceId, SPWorkflowHistoryEventType.WorkflowComment, 0, TimeSpan.Zero, "Debugging Output", updateCol, string.Empty);
service.LogToHistoryList(this.WorkflowInstanceId, SPWorkflowHistoryEventType.WorkflowComment, 0, TimeSpan.Zero, "Debugging Output", updateVal, string.Empty);
ClientContext clientContext = new ClientContext(SiteUrl);
SP.List oList = clientContext.Web.Lists.GetByTitle(List);
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<View><Query><Where><Geq><FieldRef Name='"+Column+"'/>" +
"<Value Type='String'>"+Value+"</Value></Geq></Where></Query><RowLimit>1</RowLimit></View>";
ListItemCollection collListItem = oList.GetItems(camlQuery);
clientContext.Load(collListItem);
clientContext.ExecuteQuery();
foreach (ListItem oListItem in collListItem)
{
oListItem[updateCol] = updateVal;
oListItem.Update();
clientContext.Load(oListItem);
clientContext.ExecuteQuery();
}
return ActivityExecutionStatus.Closed;
}
catch (Exception ex)
{
ISharePointService service = (ISharePointService)executionContext.GetService(typeof(ISharePointService));
if (service == null)
{
throw;
}
service.LogToHistoryList(this.WorkflowInstanceId,SPWorkflowHistoryEventType.WorkflowError, 0, TimeSpan.Zero,"Error Occurred", ex.Message, string.Empty);
return ActivityExecutionStatus.Faulting;
}
解决方法:
感谢Yevgeniy,感谢您的有益评论.我能够使用Yevgeniy建议的服务器对象模型找到解决方案. Thanks also to this blog post.以下代码解决了该问题.
using (SPSite _site = new SPSite(SiteUrl))
{
using (SPWeb _web = _site.OpenWeb())
{
SPList oList = _web.Lists[List];
SPQuery _query = new SPQuery();
_query.Query = "<Where><Eq><FieldRef Name='"+Column+"' /><Value Type='Text'>"+Value+"</Value></Eq></Where>";
SPListItemCollection _itemCollection = oList.GetItems(_query);
if (_itemCollection.Count > 0)
{
_web.AllowUnsafeUpdates = true;
foreach (SPListItem Item in _itemCollection)
{
Item[updateCol] = updateVal;
Item.Update();
}
_web.AllowUnsafeUpdates = false;
}
}
}
标签:c,sharepoint 来源: https://codeday.me/bug/20190703/1366289.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。