Welcome to K2 Underground Sign In | Join | Help
How to retrieve the value from an XML field element

Sometimes one needs to get the value from an element within a K2 XML field.  This is usually done within a Server Event.  In the below example, I needed to retrieve a URL from a K2 generated XML field.  This specific example should work if you do not expect repeating values in the Items node.  For scenarios where repeating values are selected, then the XPath would need to be changed.


            // get the full XML from the K2 XML field
            string strXML = K2.ProcessInstance.XmlFields["SPEventsField"].Value;
            // set the XPath to the desired node
            string strXPath = "/Items/Item/URL";
            // use the helper class to retrieve the value for this element (as set in the XPath) for this XML
            string strValue = SourceCode.Workflow.Common.XmlHelper.GetXPathValue(strXML, strXPath);

 

 

Published Wednesday, July 09, 2008 10:25 AM by Bob

Comments

# re: How to retrieve the value from an XML field element @ Wednesday, July 09, 2008 8:38 AM

Bob,

In your post you mentioned "K2 generated Xml" in the XML field. I'm having a hard time understanding the XML fields vs. "plain old" fields in the K2 process. Could you do a brief blurb/post on what the K2 xml fields exist for, how they're used, etc.?

Thanks!!

endpointsys

# re: How to retrieve the value from an XML field element @ Thursday, July 17, 2008 2:33 AM

I found the xml field useful for stuffing bunch of users and use them as destination users.  I blogged about it at http://geeks.netindonesia.net/blogs/jimmy/archive/2008/05/08/k2-blackpearl-lesson-learnt-uhm-so-far.aspx

jchandra

# re: How to retrieve the value from an XML field element @ Monday, July 28, 2008 8:53 PM

XML fields provide the ability to store multiple values within a single field.  Furthermore since XML has structure to it, K2 provides the ability to drill down to individual elements of it when using an XML field within K2 design time tooling like in Line Rules and Wizards.

Bob

Anonymous comments are disabled
Powered by Community Server (Commercial Edition), by Telligent Systems