Tuesday, 21 August 2018

Exporting Mapping Details as Spreadsheet/Excel in SAP CPI

Exporting Mapping Details as Spreadsheet/Excel in SAP CPI:

Procedure:
  1. In Eclipse >Choose software component version > namespace > Message Mapping.
  2. Select the mapping that you want to export to spreadsheet format.
  3. From that right click on the selected mapping, choose Export as Spreadsheet.
  4. In the Save As dialog, select the location for saving the spreadsheet containing the mapping details.
  5. Choose Save.
Export mapping to Excel is successful.

For SAP PI mapping export to spreadsheet/Excel:

Procedure

  1. Export mapping to XMI file from SAP PI.
  2. Then upload the file in https://figaf.com/services/pi-documenter-pi-diff/
  3. Select the Excel format you need it.
  4. Click on Generate documentation
Export mapping to Excel is successful.




Wednesday, 15 August 2018

SAP_IsIgnoreProperties property use in SAP CPI/ SAP HCI


Tried lot in google about this property, but I couldn't find the usage of this below property used in the script. If anyone has idea can update in below comments will be useful for other too.

Soon I will try to find and update it.

Groovy Script:

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

def Message processData(Message message) {
//Set header SAP_IsIgnoreProperties
message.setHeader("SAP_IsIgnoreProperties",new Boolean(true));

return message;
}



YMkt application integration via SAP CPI/ SAP HCI

Below is an idea on how we are connecting to the YMkt application/system

There are two ways to connect to YMkt application. Basically YMkt is a ODATA application.

1. Through ODATA adapter in CPI
2.Through HTTP Adapter in CPI

When using ODATA adapter, can directly access the application.
But when accessing via HTTP adapter, then X-CSRF token exchange must be happened.

CSRF token Handling:

By using content modifier at before step, we need to pass in Header parameter as

x-csrf-token - constant - value as fetch

Set Cookie using groovy script:

Even set cookie needed to pass it to Ymkt receiver application.

import com.sap.gateway.ip.core.customdev.util.Message;
import groovy.xml.*;
import java.io.*;

def Message processData(Message message)
{
    def headers = message.getHeaders();
    def cookie = headers.get("Set-Cookie");
    StringBuffer bufferedCookie = new StringBuffer();
    for (Object item : cookie)
    {
        bufferedCookie.append(item + "; ");     
    }
    message.setHeader("Cookie", bufferedCookie.toString());
   
   
    def messageLog = messageLogFactory.getMessageLog(message);
    if(messageLog != null)
    {
        messageLog.setStringProperty("Logging_Cookie", bufferedCookie.toString());
    }
    return message;
}



To set Header using groovy script in SAP CPI/ SAP HCI

You can add this below script and achieve to add the header to the content

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
  message.setHeader("Content-Type", "text/xml" + "; charset=utf-8" );
  return message;

}



Monday, 30 July 2018

WstxUnexpectedCharException: Unexpected character in prolog; expected '<'

Are you getting this below error:

Could not generate the XML stream caused by: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character 'C' (code 67) in prolog; expected '<'
 at [row,col {unknown-source}]: [1,1]., cause: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character 'C' (code 67) in prolog; expected '<'
 at [row,col {unknown-source}]: [1,1]

Solution:

Note: below comment on this error is not exact solution always, depend on the steps it may vary. This is one of the cause.

1. This is due to structure data mismatch to the next step.

If it is mapping step then source wsdl and the input data structure/namespace to it is different. It is expecting <xml version ........ at 1st line but that is not present. 

2.   Operation specification at header field in mapping level is  mentioned constant( instead of Create/Update etc.)



Count row/ line from csv file in SAP HCI/CPI

We had a requirement to count the lines in CSV file and return the value at end of that payload.

For this, we had written a groovy script to count the lines and return it to store in property . By that we retrieved it in the content modifier.


Code:

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

def Message processData(Message message) {
def lineNo = 0;
def lines = message.getBody(java.lang.String) as String;
    lines.eachLine {
    lineNo++} 
message.setProperty("count1",lineNo);
return message;
}

Content Modifier:

Add this in body to print the count of the lines

${property.count1}



Tuesday, 3 July 2018

Collecting a field from different input structure and pass it to SuccessFactor Query

I have a requirement, where we need to pick all the personIdExternal fields from the source data (may be different structure as well) and combine all then pass it to the query at the receiver channel.

From all the values, If any of the personIdExternal value is matching at SuccessFactor need to be fetch as response.

Groovy Script:

import com.sap.gateway.ip.core.customdev.util.Message;
import groovy.json.*;
import groovy.util.logging.*;
import com.sap.gateway.ip.core.customdev.util.Message;
import org.codehaus.*;

def Message processData(Message message)
{

 def body = message.getBody(java.lang.String) as String;
 def XmlDataObject = new XmlSlurper().parseText(body)

    def xmldata = []
    def s="";
    XmlDataObject.'**'.findAll { it.name()== 'personIdExternal'}.each { a ->
    xmldata << a.text() }

//Removed duplicates

    xmldata.unique()   
    def last = xmldata.last()

//Need to find the last value to remove "or" from it

    for (i in xmldata){
     
       if (last == i){
      
          s= s.concat("(personIdExternal eq ${i}) ");
          }
       else{
             s= s.concat("(personIdExternal eq ${i}) or ");
           }
               }
    message.setBody(s);
    return message; 
    }

Output:


(personIdExternal eq 101) or (personIdExternal eq 112) or (personIdExternal eq 123) or (personIdExternal eq 144) or (personIdExternal eq 115) or (personIdExternal eq 167) or (personIdExternal eq 179) or (personIdExternal eq 189) or (personIdExternal eq 136) or (personIdExternal eq 182)


Happy Learning!!!