Sharepoint Out of the box Approval Workflow Approve/Reject comments issue when programmatically altering it

喜夏-厌秋 提交于 2019-12-04 22:34:49

To add a comment to a task when you Approve/Reject it, you just need to use the line before AlterTask:

ht["ows_FieldName_Comments"] = comments;

After the task is approved you can see the comments in the Workflow History List.

You can also get all the consolidated comments from a task with:

Hashtable extProperties = SPWorkflowTask.GetExtendedPropertiesAsHashtable(currentTask);

string consolidatedComments = extProperties["FieldName_ConsolidatedComments"].ToString();

Good luck!

If you need code only for Lists (not for DocLibs) you can use item.ModerationInformation.Status property. Like the the following example:

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();

But if you want to do it for all list types, you can use internal method UpdateInternal, with the following parameters:

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);
}

You can use examples from this russian blog Item ModerationInformation and SPListItem.UpdateInternal()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!