Welcome to K2 Underground Sign In | Join | Help

Johnny's K2 Blog

Just a place to share my K2 related thoughts/tips/tricks with the community. - Johnny Fang, Solutions Manager, K2
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());

            }

 

Posted: Monday, July 21, 2008 12:12 PM by johnny

Comments

man_anja said:

Hello Johnny,

this seems very helpful - is there a possibility to get the user who has finished the task to store him back to the form?

Anja

# July 25, 2008 2:16 AM

man_anja said:

Hello Johnny,

one additional question: When do this code run? I have an event within the same Activity (directly after the InfoPath Client Event) and I fear the changes I made in the form during the suceeding rule are not available there.

Anja

# July 25, 2008 4:12 AM

johnny said:

Ok this depends a bit on the destination rule options.  My new article on this might help to make a bit of sense on this.  http://k2underground.com/blogs/johnny/archive/2008/07/26/differences-between-plan-just-once-and-plan-per-destination.aspx

The gist is that it depends on how many activity instances are created.  So you could store the results back into the form but you would need to traverse either the slots collection (if using "Plan Just Once") or log the individual actions seperately each time the succeeding rules first (if using "Plan per Destination).  I'll edit this article to include an example to retrieve the actions per slot.

# July 28, 2008 1:07 AM
Anonymous comments are disabled