Wednesday, February 23, 2022

Split one field value using groovy script and sent to two output fields in SAP CPI

 Split the value from one input field using space and return to two output fields.


Groovy Scripts:

import com.sap.it.api.mapping.*;

def void ReadNames(String[] ID,Output Fname ,Output Lname,MappingContext context)

{

    def Fname_L = ID[0].substring(0,ID[0].indexOf(' '));

    def Lname_L = ID[0].substring(ID[0].indexOf(' ')+1, ID[0].length())

    Fname.addValue(Fname_L);

    Lname.addValue(Lname_L);

}

(or)

import com.sap.it.api.mapping.*;

def void substring_value(String[] CC, Output output, MappingContext context)

{

String[] list = CC[0].split(" ");

if (list.length > 0)

{

for (int j = 0; j < list.length; j++)

{

output.addValue(list[j]);

} }

}


Input-Ramesh Kumar

Output:

First field-Ramesh

Second field-Kumar

Friday, February 4, 2022

Two files in SFTP will have different headers in CSV format.

 * There will be 2 files in sftp 1. Create and 2.Update both files will have different header in CSV format.

 * Create file will have 7 header and the update file will have 3 header.

Example :

Create filename - ActivityCFile

Update filename-ActivityUpdateFile

Step:1

In Content Modifier read the sftp file name using ${file:onlyname.noext},


Step:2
 
Use Router condition to check the file name with 'ActivityC' or not- ${property.Filename} contains 'ActivityC' 

* Contains means it will check the file name with 'ActivityC' then it will satisfy the condition.


After the router condition, we can convert csv to xml and proceed based on requirement.








Thursday, February 3, 2022

Externalizing a parameter in content modifier and using inside Message Mapping Field level for dynamically

 Instead of using an external parameter type, use either “Constant” or “Expression” type within content modifier. And in the value column, define the external parameter.

Example:



Using groovy script, we can access inside Mapping field level dynamically value.


import com.sap.it.api.mapping.*;

def String ReadExternalProperty(String P1,MappingContext context) {

  String messageID = context.getProperty(P1);

   return messageID

  }


(or)

import com.sap.it.api.mapping.*;

import com.sap.it.api.mapping.MappingContext;

def String getProperty(String property_name, MappingContext context) {

    def propValue= context.getPropery(property_name);

   return propValue;

}


In mapping, we need to use groovy script and  call field  names maintained in Content modifier.




The sender will pass the data in JSON format without converting it to XML format. We need to read the particular field.

The sender will pass the data in JSON format without converting it to XML format. We need to read the particular field to check the conditio...