Thursday 7 September 2023

Find or remove duplicate record from the excel, csv, txt files online

 Online tool to Find or remove duplicate record from the excel, csv, txt files 


mynikko.com/tools/tool_duplicateremover.html




Monday 21 August 2023

Sap cpi new adapter error


Error: {"message":"EXCEPTION","parameters":["java.util.concurrent.TimeoutException"]},{"message":"UNRESOLVED","parameters":["(&(component=aws)(objectClass=org.apache.camel.spi.ComponentResolver))"]}]}


Solution:
After adding the adapter to the artifact you have to deploy the adapter manually.









Tuesday 8 August 2023

Pick all the values from XML and check for the condition using groovy script in SAP CI



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

import java.util.HashMap;

import java.text.SimpleDateFormat;

import java.util.TimeZone;

import org.joda.time.*;

import groovy.json.*


def Message processData(Message message) {

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

def scs = new XmlSlurper().parseText(body)


def accno = scs.InvTransDoc.InventoryTransaction.'**'.find {it.name() == 'AccountNumber'}?.text()

def fromLocCode = scs.InvTransDoc.InventoryTransaction.'**'.find {it.name() == 'fromLocationCode'}?.text()

def toLocCode = scs.InvTransDoc.InventoryTransaction.'**'.find {it.name() == 'toLocationCode'}?.text()


if(fromLocCode == "FSLHOLD" | fromLocCode == "FSLDAMAGED" | fromLocCode == "FSLMISSING")

{

message.setHeader("LocationCode",toLocCode);

}

else

{

message.setHeader("LocationCode",fromLocCode);

}

message.setHeader("StorLoc",accno);

return message;

}












Get the dynamic date's and return using groovy script in SAP CI

Based on the input day from the value mapping this returns, incase if the date's are changing later then it is config change only.

Groovy Script:


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

import java.util.HashMap;

import groovy.json.JsonSlurper

import groovy.json.JsonException

import groovy.json.JsonOutput

import javax.xml.*;

import groovy.xml.*


def Message processData(Message message)

{
def propertyMap = message.getProperties()

String date2 = propertyMap.get("ExectutionDate");

String date3 = propertyMap.get("ExectutionDate1");

String date4 = propertyMap.get("ExectutionDate2");

def date1 = new Date()

String day = date1.getDate()

if (day == date2 || day == date3 || day == date4 )


{

Flag = "true"; 

}


else {

Flag = "false" 

}

message.setProperty("Flag1", Flag)

message.setProperty("day1", day)

return message;

}







Pick the certain date's of the month as output in mapping in SAP CI


There is a requirement where the report should run on certain date on every month, so this below logic is implement in mapping to achieve this.


Groovy script:


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

import java.util.HashMap;

import groovy.json.JsonSlurper

import groovy.json.JsonException

import groovy.json.JsonOutput

import javax.xml.*;

import groovy.xml.*


def Message processData(Message message) {

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

def date = new Date()

def day = date.getDate()

def Flag = ""


if(day == 20 || day == 21 || day == 22 || day == 23){

Flag = "true"

}

else {

Flag = "false"
}


message.setProperty("Flag",Flag)

return message;

}



Remove XML hierarchy (multiple levels)nodes from the xml



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

import java.util.HashMap;

import groovy.xml.XmlUtil;

import groovy.util.*;


def Message processData(Message message) {

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

def xml = new XmlSlurper().parseText(body)

xml.Lines.SerialNumber.Sub_Component.children().findAll { it.name() == 'SubCompDescription' }.replaceNode {}


xml.Lines.SerialNumber.children().findAll { it.name() == 'ItemDescription' }.replaceNode {}

body = XmlUtil.serialize(xml)

message.setBody(body);

return message;

}







Find all the messages from the unformatted xml and place in newline




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

import java.util.HashMap;

import groovy.xml.XmlUtil;

import groovy.util.*;


def Message processData(Message message) {

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

def xml = new XmlSlurper().parseText(body)

def error = xml.'**'.findAll { it.name() == 'message' }*.text().join('\n')

message.setBody(error);

return message;

}