Thursday, December 14, 2023

Checking payload content cpi groovy.

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import java.lang.*;
import com.sap.it.api.mapping.*;
def Message processData(Message message)
{
   
       def body = message.getBody(java.lang.String) as String;
               
                // Check if the payload contains "*997*"
                if (body.contains("997")) {
                    // If "*997*" is present in the payload, perform some action or log a message
               println "Payload contains *997*"
                    // Add your code here for the action you want to perform when *997* is found
                } else {
                    // If "*997*" is not present in the payload
                println "Payload does not contain *997*"
                    // Add your code here for the scenario when *997* is not found
                }
                return message;
}




---------------

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

import java.util.HashMap;


def Message processData(Message message)

{

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


    // Split the payload into lines

    def lines = body.split("\\r?\\n");


    // Check if the payload contains "*997*" in the 3rd line starting with "ST"

    if (lines.length >= 3 && lines[2].startsWith("ST") && lines[2].contains("*997*")) {

        // If the condition is met, perform your desired action here

        // For example, you can print a message

        println("The payload contains *997* in the 3rd line starting with ST");

        // Or you can set a flag or perform any other necessary logic

        // For example, set a flag in a HashMap

        HashMap<String, Object> properties = message.getProperties();

        properties.put("Contains997", true);

        message.setProperties(properties);

    }


    return message;

};


0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home