Using a K2 connect transformation to return XML data properly

When working with K2 connect in the scenario where you want to return multiple structures from a BAPI call, you have some limitations on how the data is mapped back to the SmartObject fields.  So you would eventually reach the point where you decide to return the structure data as a XML string to a SmartObject field (e.g. the list of error codes returned by a BAPI).  Now this is pretty easy as all you have to do is to mark the structure as a XML property in the return structure as indicated in the diagram below.

Now passing in an XML structure to the BAPI call works fine.  However, the problem comes about when returning a XML structure.  If you execute the call, you will notice that the data gets returned but all the XML tags are stripped (i.e. "<" and ">").  This results in an ugly concatenated mess of jumbled data.  Now this is currently an issue with the SmartObject layer as it doesn't correctly recognize the encoded XML string from the K2 connect service broker as an XML string (Note that we do not have an XML type for SmartObject fields).  If you turn SmartObject logging on, you will see that the service broker returns the encoded XML string properly.

So at this point, you might stuck and wondering how we can get this to work properly.

K2 connect transforms to the rescue!

With the use of a custom function mapping a some simple transformation code, we can fix this.

Now in this example, I am using the BAPI_EMPLOYEE_GETDATA as an example.  Basically, I have configured the PERSONAL_DATA structure to return as an XML property.

My RETURNDATA property is configured as a text string so I need to add a transformation mapping to map the structure data as an XML string.  So I am going to use the following code.

After I do this, deploy the SVD and create the SmartObject that wraps around this (this is basic SO stuff so I am going to skip it).

Now if you execute the call in the SmartObject tester tool, you will see this.

Note that the return data retains all the proper XML brackets.  Isn't it great? :)

Now for those who have difficulty following these steps, I have also included my SVD file for reference (See HRHelper.zip).

I hope this helps some of the people out there who have hit this issue and don't really know how to get this working.  Enjoy!

N.B. All testing with done on K2 connect v3.0 with the KB000527 patch.


Posted Wed, Nov 25 2009 10:35 AM by johnny
Attachment: HRHelper.zip