Note that there are some explanatory texts on larger screens.

plurals
  1. POProgramatically Approve/Reject workflows and add comments
    primarykey
    data
    text
    <p>I'm trying to programatically approve/reject workflows in SharePoint. I can successfully do this, but I cannot add comments. I got my code from a year <a href="https://stackoverflow.com/questions/7752534/sharepoint-out-of-the-box-approval-workflow-approve-reject-comments-issue-when-p">old question</a>, which hasn't been answered either, so I thought I'd start a new question.</p> <p>My code:</p> <pre><code>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 (param == "Approved") { ht[SPBuiltInFieldId.WorkflowOutcome] = "Approved"; ht["TaskStatus"] = "Approved"; if (!string.IsNullOrEmpty(comments)) { ht[SPBuiltInFieldId.Comments] = comments; ht["Comments"] = comments; ht[SPBuiltInFieldId.Comment] = comments; } } else { ht[SPBuiltInFieldId.WorkflowOutcome] = "Rejected"; ht["TaskStatus"] = "Rejected"; if (!string.IsNullOrEmpty(comments)) { ht[SPBuiltInFieldId.Comments] = comments; ht["Comments"] = comments; ht[SPBuiltInFieldId.Comment] = comments; } } ht["FormData"] = SPWorkflowStatus.Completed; bool isApproveReject = AlterTask(task, ht, true, 5, 100); 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 &lt; 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); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload