Monday, March 7, 2022

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 :






No comments:

Post a Comment