on ‎2022 Apr 11 1:26 PM
Help others by sharing your knowledge.
AnswerRequest clarification before answering.
Hi Avrik,
You can use JsonSlurper.
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.json.JsonSlurper;
def Message processData(Message message)
{
def body = message.getBody(String);
def map = new JsonSlurper();
def object = map.parseText(body)
def id = object.data.id[0].toString()
message.setHeader("id",id )
return message
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Priyanka,
The above code working perfectly however, I want to fetch the 'id' value starting with "Asset" only.
Suppose there are 4 'id' fields in the json payload and I want to capture the last one (starting with 'Asset' and occurrence is random). Please advise.
"id":"Batch:6166a7e352faff0007dfa7dc",
"id":"assetTypeID:6166a7e352faff0007dfa7dc",
"id":"assetType:6166a7e352faff0007dfa7dc",
"id":"asset:6166a7e352faff0007dfa7dc",
Try with this.
import com.sap.gateway.ip.core.customdev.util.Message
import groovy.json.JsonSlurper
def Message processData(Message message)
{
def body = message.getBody(String)
def map = new JsonSlurper()
def object = map.parseText(body)
object.data.id.each { key ->
if (key.toString().startsWith('asset:'))
message.setHeader("id",key)
}
return message
}
| User | Count |
|---|---|
| 9 | |
| 7 | |
| 6 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.