Friday, 30 November 2018

Iflow Error in CPI

If you are facing the below issue in CPI without any proper logs, then there is configuration missing in content modifier.

In the earlier version of CPI at the content modifier, we may not provide the expressions like(${in.body}) to bypass the data flow from previous step, but now there is two options available in content modifier body
1. Constant
2. Expression

Do you need to pass the actual data out from content modifier, then Choose Expression - ${in.body}


Error Details

[CAMEL][IFLOW][ERROR] : Integration flow failed. [CAMEL][IFLOW][EXCEPTION] : org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to initialize bean .camelBlueprint.factory.Split_Router

[CAMEL][IFLOW][CAUSE] : Cause: java.lang.IllegalArgumentException: Route Process_78 has no outputs: Route(Process_78)[[From[direct:Process_78]] -> []]


!!! Hope this resolves your issue !!!



Thursday, 22 November 2018

How to route to different receiver based on the CSV file

In this blog, we discuss about how to read each line from CSV file and route it depends on the value from first field.

Sample Input data:

1158|Join
1159|Enhanced
1159|IN|980||92|193|GoTest|||20183|||||IND|India CC|5225||||||
1159|END_OF|BEART
1159|BEG|20181003
1158|EN
1159|EN


Based on 1158 and 1159 it needs to be routed.

IFLOW:

For testing purpose, we are passing the input data in content modifier












We are getting the data one by one in a separate mail. The requirement is to send a mail on the combined one. As there is a SAP standard, we can't use Gather after Router. Working on the  resolution.



Tuesday, 23 October 2018

Add one day to the input date in SAP HCI/CPI

Increment the date with day by 1.

Received a requirement to add one day to the input date. Script is implemented in the mapping level to achieve this functionality.

Groovy Script:


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

def String IncrementDateByOne1(String dateInput){

def dateFormat = 'yyyy-MM-dd'
try{
//For any date
def dateString = dateInput
def date = Date.parse(dateFormat, dateString)
//log.info date.nextDay()

            return date.nextDay()
}
catch(Exception ex){
    return ""
}
}

Input: 2012-01-03 19:10:10
Output: 2012-01-04



Monday, 15 October 2018

Trim Functionality using the Groovy Script in SAP CPI



Trim:
String str = " dsfdsf ";

String trimmedStr = str.trim();


println trimmedStr;



Pick the Iflow Name in Camel Expression in SAP CPI

For Picking up the Iflow name in the iflow and pass to fields, we can use this and achieve it.

   ${camelId}



Camel Expressions available in SAP CPI

Parameter Description
${in.body} or ${body} Message Payload
${header.var1} Message Header Variable (var1)
${property.prop1} Exchange Property (prop1)
${date:now:yyyy-MM-dd} Current Date/Time with format
${property. SAP_MessageProcessingLogID} Message Guid
${CamelFileName} File Name
${CamelHttpUri} HTTP URI (URL with QueryString)
${CamelDestinationOverrideUrl} SOAP Adapter URL
${exception.message} Error Message
${exception.stacktrace} Error Stacktrace
${camelId} Iflow Name
${SAP_ApplicationID} ID created in Message Processing Log for searching in monitoring
Relative Paths
Expression Returns
file:absolute FALSE
file:absolute.path \workspace\camel\camel-core\target\filelanguage\test\hello.txt
file:ext txt
file:name test\hello.txt
file:name.ext txt
file:name.noext test\hello
file:onlyname hello.txt
file:onlyname.noext hello
file:parent filelanguage\test
file:path filelanguage\test\hello.txt
Absolute Paths
Expression Returns
file:absolute TRUE
file:absolute.path \workspace\camel\camel-core\target\filelanguage\test\hello.txt
file:ext txt
file:name test\hello.txt
file:name.ext txt
file:name.noext test\hello
file:onlyname hello.txt
file:onlyname.noext hello
file:parent \workspace\camel\camel-core\target\filelanguage\test
file:path \workspace\camel\camel-core\target\filelanguage\test\hello.txt



Friday, 5 October 2018

Picklist/ Lookup comparison in SAP CPI/HCI

Lookup and compare the two payload from the input and try to filter out the <label> field and return it.


Test data:

<?xml version="1.0" encoding="UTF-8"?>
<multimap:Messages
xmlns:multimap="http://sap.com/xi/XI/SplitAndMerge">
<multimap:Message1>
<Picklist>
<Picklist>
<optionId>301</optionId>
<locale>en_GB</locale>
<label>Permanent</label>
</Picklist>
<Picklist>
<optionId>346</optionId>
<locale>en_GB</locale>
<label>Associate</label>
</Picklist>
<Picklist>
<optionId>304</optionId>
<locale>en_GB</locale>
<label>Active</label>
</Picklist>
<Picklist>
<optionId>352</optionId>
<locale>en_GB</locale>
<label>Permanent</label>
</Picklist>
</Picklist>
<Employee>
<EmpEmployment>
<EmpEmployment>
<startDate>2018-04-01T00:00:00.000</startDate>
<personIdExternal>50000006</personIdExternal>
<userId>50000006</userId>
<endDate></endDate>
</EmpEmployment>
<EmpEmployment>
<startDate>2018-05-09T00:00:00.000</startDate>
<personIdExternal>50000006</personIdExternal>
<userId>3</userId>
<endDate></endDate>
</EmpEmployment>
</EmpEmployment>
<EmpJob>
<EmpJob>
<userId>50000006</userId>
<employeeClass>352</employeeClass>
</EmpJob>
<EmpJob>
<userId>3</userId>
<employeeClass>346</employeeClass>
</EmpJob>
</EmpJob>
</Employee>
</multimap:Message1>
</multimap:Messages>


Output:

Permanent
Associate

GroovyScript:

def Message processData(Message message) {
    def body = message.getBody(java.lang.String) as String
    def root = new XmlSlurper().parseText(body)
    def xmldata1 = []


    def xmldata2 = []
    def xmldata3 = []
    def i=0;
    def j=0;
       root.'**'.findAll { it.name() == 'optionId'}.each { a ->
    xmldata1 << a.text()}
    root.'**'.findAll { it.name() == 'label'}.each { a ->
    xmldata2 << a.text()}
    root.'**'.findAll { it.name() == 'employeeClass'}.each { a ->
    xmldata3 << a.text()}
  
    for(j = 0; j < xmldata3.size(); j++)
    {
    for(i = 0; i < xmldata1.size(); i++){
   
        if( xmldata1[i] == xmldata3[j])
        {
       return xmldata2[i]   
        }
}
   }
}