cancel
Showing results for 
Search instead for 
Did you mean: 

Groovy script to restrict payload based on a Value in payload

vinaykumardigaveedi
Participant
0 Kudos

Hello Experts,

We need a groovy script to stop the payload. If the payload contains " Aircycle" the iflow should pass the data & If the payload contains "Energy" it should be stopped in CPI.

Could any one help me with this issue?

Thanks,

Vinay

Accepted Solutions (0)

Answers (1)

Answers (1)

MartyMcCormick
Product and Topic Expert
Product and Topic Expert

Hello

Assuming you that don't have XML where you can use an XPath and literally just want to check the message payload to see if the value exists, you can use the following in a script step and then have a router after the script to either continue or raise the end message based on the property value of p_continue.



def body = message.getBody(java.lang.String) as String;
def messageLog = messageLogFactory.getMessageLog(message); 
def pMap = message.getProperties(); 

if(body.contains("Aircycle")) { 

message.setProperty("p_continue", "TRUE"); 

} 

else { 

message.setProperty("p_continue", "FALSE"); 

}

Thanks,
Marty

vinaykumardigaveedi
Participant
0 Kudos

Hello Marty,

Thanks for the quick reply.

If I am getting an Individual payload, It works.

But when I get a Combined payload , which has Aircycle data & Energy data, It doesn't work. Both the data passes to the target.

We are using Splitters & filter to separate the individual data. What steps or Groovy script can be developed in the Iflow to pass only the AirCycle data after splitting & filter pallets.

Thanks,

Vinay

MartyMcCormick
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Vinay

In this case, the simplest approach would be to move your script step as the first step inside the splitter. Then you can check each record individually to make a determination.

Thanks,
Marty