Wednesday, 8 May 2019

ERROR: Moving type h to type g is not supported termination: RABAX_STATE

When there is a similar issue raised in the CPI open view logs, then we might check with the target system as there might be logic/variable maintained in different format/not acceptable, so the values can't be updated in their system.

Cause of the issue: May be there is datatype mismatch, data format issues, can't update in the read only fields.




Friday, 5 April 2019

XML tag/XML Node removal from XML data


When required to remove the xml tag from the xml data for the futher transformation steps, then below grovvy script will be used to achieve this functionality.

Groovy Script:


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


def Message processData(Message message) {

//Body

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

body = body.replaceAll("\\<\\?xml(.+?)\\?\\>", "").trim();

message.setBody(body);

return message;

}



Thursday, 4 April 2019

ODATA filter for Mobile number

When trying to use the mobile number filter criteria in the ODATA functionality, it may not retrieve the data, so there is solution for it.

https://myXXXXX.crm.ondemand.com/sap/c4c/odata/v1/c4codataapi/IndividualCustomerCollection?$filter=Phone eq %2B91 9873263245'

The special character + Indicates a space (and spaces cannot be used in a URL) so you need to replace the character with its hexadecimal value as %2B.

Your corrected filter should then be $filter=Mobile eq '%2B46 123456789'



Sunday, 31 March 2019

Form ODATA V2 query parameters like filter,top,skip dynamically

This groovy script describes about the formation of the filter, top, skip query option in the receiver ODATA adapter for the V2 protocol.

Groovy script:


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

import java.util.HashMap;

import org.apache.olingo.odata2.api.uri.UriInfo;

import com.sap.gateway.ip.core.customdev.logging.*;


def Message processData(Message message) {   

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

    def messageLog = messageLogFactory.getMessageLog(message);

def uriInfo = message.getHeaders().get("UriInfo");

/*

The following script copies the content of UriInfo into the respective fields for OData receiver.

Reference for UriInfo:com.sap.gateway.core.ip.provider.data.UriInfoImpl.java

In OData Reciever use {header.odataEntity}?{header.odataURI}

*/

def odataURI = new StringBuilder();

def urlDelimiter = "&";

def urlConcat = "?";

def entityName = uriInfo.getTargetEntitySet().getName();

log.logErrors(LogMessage.TechnicalError, "Entity Name::"+entityName);

/*

if (uriInfo.getTop() != null){

def top = uriInfo.getTop();

if(odataURI.size()!=0)

odataURI.append(urlDelimiter);

odataURI.append("\$top=").append(top);

log.logErrors(LogMessage.TechnicalError, "Top value:"+top);

}

if (uriInfo.getSkip() != null){

def skip = uriInfo.getSkip();

if(odataURI.size()!=0)

odataURI.append(urlDelimiter);

odataURI.append("\$skip=").append(skip);

log.logErrors(LogMessage.TechnicalError, "Skip value:"+skip);

}

*/

if (uriInfo.getFilter() != null){

def filter = uriInfo.getFilter().getExpressionString();

if(odataURI.size()!=0)

odataURI.append(urlDelimiter);

odataURI.append("\$filter=").append(filter);

log.logErrors(LogMessage.TechnicalError, "Filter value:"+filter);

}

log.logErrors(LogMessage.TechnicalError, "URI value:"+ odataURI.toString());



if(messageLog != null){

messageLog.setStringProperty("Logging#1", "Printing Payload As Attachment")

messageLog.addAttachmentAsString("IncidentMappingOUTPayload:", body, "text/plain");

}

//Set Headers

message.setHeader("odataEntity",entityName);

message.setHeader("odataURI",odataURI.toString());

return message;




Wednesday, 27 March 2019

Compare Date's using Groovy script in mapping in SAP CPI

If required to compare the two date's and provide the output to the field in mapping.


Groovy Script:


import com.sap.it.api.mapping.*;
import java.text.SimpleDateFormat;
import com.sap.aii.mapping.api.*;
import com.sap.aii.mapping.lookup.*;
import com.sap.aii.mappingtool.tf7.rt.*;
import java.io.*;
import java.lang.reflect.*;
import java.util.*;

/*Add MappingContext parameter to read or set headers and properties
def String customFunc1(String P1,String P2,MappingContext context) {
         String value1 = context.getHeader(P1);
         String value2 = context.getProperty(P2);
         return value1+value2;
}
Add Output parameter to assign the output value.
*/
def void custFunc2(String[] startDateJob,String[] endDateJob, String[] Field,Output output,MappingContext context) {
   
boolean out = false;
Date date1;
Date date2;
long diff;
long days;

String[] bDate;
SimpleDateFormat formatter1=new SimpleDateFormat("yyyy-MM-dd");

for(int i=0;i < startDateJob.length;i++)
    {
       
              date1=formatter1.parse(startDateJob[i]); 

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

                           try{
              date2=formatter1.parse(endDateJob[j]);
              diff = date1.getTime() - date2.getTime();
              days = diff / (24 * 60 * 60 * 1000);
             
              out = (days.equals(1));
                                }
                           catch ( java.text.ParseException e)
                           { }
                          

    if (i==0 && j==0)
              {
     output.addValue(" ");
    }
   else if (days==1)
    {
     output.addValue(Field[i]);
    }}
}
}

Thanks Shruthi for the support on this script.



To split a string at a particular character using Groovy script in SAP CPI



To split a string at a particular character from the message body, utilize the script in message mapping to split.


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

def void substring_CostCenter(String[] CC, Output output, MappingContext context)
{
String[] list = CC[0].split("_");

if (list.length > 0)
{
for (int j = 1; j < list.length; j++)
{

output.addValue(list[j]);
} }
}



Tuesday, 26 March 2019

CSV to XML converter issue on XPATH

If you are facing an error as below in the CSV to XML converter, there is a solution for it.

java.lang.IllegalStateException: Element name [] not found in provided XML schema file


Solution:

There is an issue in the XPATH defined in the CSV to XML converter:

Path to Target Element in XSD: Root/

Instead of /Root or /Root/ use as Root/