Updating Batch Action/Outcome results back into InfoPath form
I got posed this question the other day and I thought this might be useful to share.
The scenario is that when do a batch selection or quick approval action from the worklist, the outcome is not recorded into the form's audit history. Of course, the process audit history will have it but in certain cases, the user does not have access to the process history information.
So if we wanted to store the outcome in the InfoPath form data, basically we have to update the value directly within the succeeding rules of the client activity.
Here's an example. Edit the code of your succeedin rule. You can get the final outcome by putting this snippet of code inside the succeeding rule. See portions in red. The text in green is the variables you need to change to your own form and namespace.
using System.Xml;
…
public void Main(Project_282cb15964ee4ab397715563ff6641a6.SucceedingRuleContext_369ef228d5e54527b7116b0583eabd22 K2)
{
if (SucceedingRuleHelper.AnyOutcomesEvaluatedSuccessfully(K2))
{
AllInfoPathTasksFinished(K2);
K2.SucceedingRule = true;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(K2.ProcessInstance.XmlFields["TestForm"].Value);
XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xmlDoc.NameTable);
namespaceManager.AddNamespace("my", xmlDoc.DocumentElement.GetNamespaceOfPrefix("my"));
xmlDoc.SelectSingleNode("my:myFields/my:myDataField", namespaceManager).InnerText = K2.ActivityInstance.DataFields["Outcome"].Value.ToString();
K2.ProcessInstance.XmlFields["TestForm"].Value = xmlDoc.OuterXml;
}
else
{
InfoPathTaskFinished(K2);
K2.SucceedingRule = false;
}
}
Addendum:
If you are using the "Plan Just Once" option, you should note that there is only one Activity Instance created with 1 or more slots tied to it (See my article on this). So if you want to enumerate through the list of actions, here's a code snippet to do this.
for (int i = 0; i < K2.ActivityInstanceDestination.ActivityInstance.WorklistSlots.Count; i++)
{
Console.WriteLine("Action Result: " + K2.ActivityInstanceDestination.ActivityInstance.WorklistSlots[i].DataFields["Action Result"].Value.ToString());
Console.WriteLine("Destination User: " + K2.ActivityInstanceDestination.ActivityInstance.WorklistSlots[i].User.Name.ToString());
}