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;

}












No comments:

Post a Comment