Monday, March 7, 2022

Content Modifier - Concatenate Array Inputs ( Dynamic Parent Node)

 

 Requirement is to extract the repeated XML node with Dynamic Parent Nodes.






Here, we are passing the below payload directly in Content Modifier - Message Body

--------------------------------------------------------------------------------------------------------------------

<message>

    <header>

      <messageId>1</messageId>

      <masterMsgId>33300453700</masterMsgId>

      <equipment>

        <serialNumber>API TestSNVin</serialNumber>

        <make>CAT</make>

        <model>D100</model>

        <nickname>API Test Asset</nickname>

      </equipment>

      <moduleCode>API TestDeviceSN</moduleCode>

      <moduleTime>2022-02-16 10:45:14</moduleTime>

      <receivedTime>2022-02-16 10:45:14</receivedTime>

      <owner>Equipment Owner</owner>

    </header>

    <serviceMeter>

      <value>79</value>

      <uom>Hours</uom>

    </serviceMeter>

    <mileage>

      <value>13</value>

      <uom>Miles</uom>

    </mileage>

    <location>

      <latitude>7</latitude>

      <longitude>77</longitude>

      <validity>V</validity>

    </location>

  </message>

--------------------------------------------------------------------------------------------------------------------


Groovy Script:

import com.sap.gateway.ip.core.customdev.util.Message;


import java.util.HashMap;

import java.util.*;

def Message processData(Message message)

{

    def body = message.getBody(java.lang.String) as String;

    def root = new XmlParser().parseText(body);

    def i=0;

    def errors="";

    def allmessage=[];

        root.'**'.findAll { it.name() == 'value'}.each { a ->allmessage << a.text()};

    int len = allmessage.size();

    while(i<allmessage.size())

    {

        errors=errors+","+allmessage[i];

        i++;

    }

        errors=errors.substring(1);

     def messageLog = messageLogFactory.getMessageLog(message);

       if(messageLog != null){

        messageLog.setStringProperty("Logging1", "Printing Payload As Attachment");

        messageLog.addAttachmentAsString("only_message:", len + "message – "+errors, "text/plain");

     }

     message.setBody(errors);

    return message;

}




--------------------------------------------------------------------------------------------------------------------

Output:  We need the data from Value nodes

<value></value>  ,  with two Parent nodes (Dynamic) -  serviceMeter and mileage





Content Modifier - Concatenate Array Inputs

 Requirement is to extract the repeated XML node with Static parent node.




Step 1 -

Here, I am passing input in the Content modifier itself.


Sample Input:

<Root>

<Employee>

<Name>Akshay</Name>

<ID>1</ID>

</Employee>

<Employee>

<Name>Sudeep</Name>

<ID>2</ID>

</Employee>

<Employee>

<Name>Advik</Name>

<ID>3</ID>

</Employee>

<Employee>

<Name>Hirva</Name>

<ID>4</ID>

</Employee>

</Root>

-----------------------------------------------------------------------------------------------------------------------------

Step 2 :

Declare Property variables to hold the output.



Name_Concat

 string-join(/Root/Employee/Name, ",")


ID_Concat

 string-join(/Root/Employee/ID, ",")


Below is the config. of the message body tab of the content modifier:



-----------------------------------------------------------------------------------------------------------------------------

Step 3:

Using a Groovy script to log the payload

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;

def Message processData(Message message) {
def body = message.getBody(java.lang.String) as String;
def messageLog = messageLogFactory.getMessageLog(message);
messageLog.addAttachmentAsString("Payload", body, "text/plain");
return message;
}

-----------------------------------------------------------------------------------------------------------------------------


Final Output :






Tuesday, March 1, 2022

Global Data Store & Variable

 The first iFlow shows how to write a variable (Global) and Write the incoming data to a Data Store.

Whereas, in the second iFlow we will fetch data from the data store which was declared in the first iFlow. 


First iFlow (Producer)



Address :

https://refapp-espm-ui-cf.cfapps.eu10.hana.ondemand.com/espm-cloud-web/espm.svc

 


Write Variable:

Write Variables are used to share data across different integration flows (deployed on the same tenant).

To consume the variable (either in another step of the same integration flow or in another integration flow), can use a Content Modifier.

A variable gets expired after the retention period which is 400 days.



Data Store Write Operation:

This step performs a Write operation on the transient data store.

Entry ID

Specify an entry ID that is stored together with the message content. The entry ID must not exceed 255 characters.

Details for the entry ID are read from the incoming message. You can enter the following kinds of expressions:

  • ${header.headername}, to dynamically generate the entry ID from the message header.
  • ${property.propertyname}, to dynamically generate the entry ID from the exchange property of the message.
  • ${xpath.<xpath>}, to dynamically generate the entry ID from an element in the message indicated by an xPath expression.

 





Below is Log for WRITE VARIABLE Step:


 



Below is Log after Splitter step:

You will observe 18 different Segments for General Splitter in the Trace mode.

Each Splitter consisting of one CustomerReview node.

 


 


 

 

Second iFlow (Consumer)

 



This step selects entries from a transient data store and creates a bulk message containing the data store entries.


 Content Modifier 1


Content Modifier 2


 Postman :