Sending complex data to and from SAP with K2 connect can be accomplished by using XML data constructed on a schema. This schema is generated during the Service Object configuration. Previously it was the responsibility of the user to generate the XML data correctly or to interpret the XML returned from K2 connect through a SmartObject.
As from K2 connect version 4.6.5, enabling the option to create an XML property during the Service Object configuration, will now create methods to serialize or deserialize these XML data structures.
Executing these methods make it easy to read the data structure and send data into SAP.
Serialization is when the state of an object is changed to a form that can be imported or exported. Deserialization converts it back to an object.
Use the steps below as an example on how to use the Serialization and Deserialization functionality. For this example, we will use K2 Designer for Visual Studio 2012 to configure and publish a Service Object mapped to the BAPI_CUSTOMER_GETLIST BAPI. We will then use the SmartObject Service Tester exe to execute the new methods.
Creating the Service Object and SmartObject
- Open K2 Designer for Visual Studio and create an empty K2 Project.
- Add a K2 connect Service Object item to the project named Customer.
- Click on Add Service.
- Open the K2 Service Object Designer from the View menu.
- Add the BAPI_CUSTOMER_GETLIST filter to the BAPI Explorer.
- Drag the filter to the new service as per the image below.
- Click on the Service Method to open the Method Designer.
- Click on the IDRange field and click on Show Structure.
- Enable the XML Property.
- Publish the Service Object.
Test the Serialize Method
- Open the SmartObject Service Tester exe (located by default in [Program Files (x86)]\K2 blackpearl\Bin).
- Expand the Service Object Explorer.
- Expand the K2 connect Service.
- Expand the Service Instance.
- Two folders are listed namely Connect Objects and Object Types.
- Expand the Object Types folder.
- Expand your Service Object created, down to methods. You will see the new methods available.
- Expand SmartObject Explorer.
- Expand the Serialization folder.
- Right click on the CustomerIDRange SmartObject and select Execute SmartObject.
- Select the Serialize method to execute.
- Click on Generate Data.
- Click on Execute.
- Note the Serialized item in the Results. That Serialized String can now be used in other methods.
Test the Deserialize Method
- To Deserialize the string, copy the Serialized string.
- Click on the Method to Execute dropdown and select Deserialize.
- Paste the Serialized string in the available property.
- Click on Execute.
- Note the Deserialized item.