我有一个可重复使用的开箱即用的sharepoint批准工作流程2010,我使用infopath formcode(2010)中的以下代码片段以编程方式批准/拒绝工作流程。
Hashtable ht = new Hashtable();
ht[SPBuiltInFieldId.Completed] = "TRUE";
ht["Completed"] = "TRUE";
ht[SPBuiltInFieldId.PercentComplete] = 1.0f;
ht["PercentComplete"] = 1.0f;
ht["Status"] = "Completed";
ht[SPBuiltInFieldId.TaskStatus] = SPResource.GetString
(new CultureInfo((int)task.Web.Language, false),
Strings.WorkflowStatusCompleted, new object[0]);
if (isApprove)
{
ht[SPBuiltInFieldId.WorkflowOutcome] = "Approved";
ht["TaskStatus"] = "Approved";
ht[SPBuiltInFieldId.Comments] = "Approved by Manager";
ht["Comments"] = "Approved by Manager";
}
else
{
XPathNavigator navigatorRejectComments
= this.MainDataSource.CreateNavigator().SelectSingleNode
(XPATH_REJECT_COMMENTS, this.NamespaceManager);
ht[SPBuiltInFieldId.WorkflowOutcome] = "Rejected";
ht["TaskStatus"] = "Rejected";
ht[SPBuiltInFieldId.Comments] = navigatorRejectComments.Value.Trim();
ht["Comments"] = navigatorRejectComments.Value.Trim();
}
ht["FormData"] = SPWorkflowStatus.Completed;
web.AllowUnsafeUpdates = true;
isApproveReject = AlterTask(task, ht, true, 5, 100);
web.AllowUnsafeUpdates = false;
任务更改方法
private static bool AlterTask(SPListItem task, Hashtable htData, bool fSynchronous, int attempts, int millisecondsTimeout)
{
if ((int)task[SPBuiltInFieldId.WorkflowVersion] != 1)
{
SPList parentList = task.ParentList.ParentWeb.Lists[new Guid(task[SPBuiltInFieldId.WorkflowListId].ToString())];
SPListItem parentItem = parentList.Items.GetItemById((int)task[SPBuiltInFieldId.WorkflowItemId]);
for (int i = 0; i < attempts; i++)
{
SPWorkflow workflow = parentItem.Workflows[new Guid(task[SPBuiltInFieldId.WorkflowInstanceID].ToString())];
if (!workflow.IsLocked)
{
task[SPBuiltInFieldId.WorkflowVersion] = 1;
task.SystemUpdate();
break;
}
if (i != attempts - 1)
Thread.Sleep(millisecondsTimeout);
}
}
return SPWorkflowTask.AlterTask(task, htData, fSynchronous);
}
此代码工作正常,但任务的注释不会被更改,也不会包含在电子邮件中。我使用的ht [“评论”]有什么问题吗?它在任务评论中没有被改变。这是我正在使用的SharePoint 2010工作流程和infopath表单也是2010年。
有人遇到过类似的问题吗?
答案 0 :(得分:2)
如果您只需要列表代码(不适用于DocLibs),则可以使用item.ModerationInformation.Status
属性。如下例所示:
var url = @"http://server/Lists/ContentApList";
var web = new SPSite(url).OpenWeb();
var list = web.GetList(url);
var item = list.GetItemById(1);
item["MyCheck"] = "test23";
item.ModerationInformation.Status = SPModerationStatusType.Pending;
item.ModerationInformation.Comment = "my coment";
item.SystemUpdate();
但是,如果要对所有列表类型执行此操作,可以使用内部方法UpdateInternal
,并使用以下参数:
static void UpdateMigrate(SPListItem item)
{
UpdateInternal(item, true, false, Guid.Empty, true, false,false, false, false, false);
}
static void CheckList5()
{
var url = @"http://server/Lists/ContentApList";
var web = new SPSite(url).OpenWeb();
var file = web.GetFile("CheckDocLib/logo.gif");
var item = file.ListItemAllFields;
item["MyComments"] = "test23ddd";
item.ModerationInformation.Status = SPModerationStatusType.Approved;
item.ModerationInformation.Comment = "my coment";
UpdateMigrate(item);
}
您可以使用此俄罗斯博客中的示例Item ModerationInformation and SPListItem.UpdateInternal()
答案 1 :(得分:1)
要在批准/拒绝任务时向任务添加注释,只需在AlterTask之前使用该行:
ht["ows_FieldName_Comments"] = comments;
任务批准后,您可以在工作流历史记录列表中看到评论。
您还可以通过以下方式获取任务的所有合并评论:
Hashtable extProperties = SPWorkflowTask.GetExtendedPropertiesAsHashtable(currentTask);
string consolidatedComments = extProperties["FieldName_ConsolidatedComments"].ToString();
祝你好运!