I need to find a record with event Hire in job_information.
def Message processData(Message message) {
//Get body from message
def body = message.getBody(java.lang.String)
//Parse body
def queryCompoundEmployeeResponse = new XmlSlurper().parseText(body)
queryCompoundEmployeeResponse.CompoundEmployee.each{
it.person.employment_information.each{
def startDate = it.job_information.find{
j->(j.event.text() == 'H')
}.start_date.text()
}
}
However, for this employee, there are 2 records at the same date. And the find function return nothing.
Anyone know how to solve this issue?
Unfortunately, I think less people know what you are talking about and I do not have any message from employee compound available, this is why I simulated the message of yours and try to show how to get each event type H, no matter what date it has.
This should search event H and return each person-node, no matter if date is equal to each other.
def stringXML =
'<personDatabase>'+
' <person><firstName>John</firstName><lastName>Doe</lastName><created>2016-05-23T09:41:39.000Z</created><event>H</event></person>'+
' <person><firstName>Jane</firstName><lastName>Smith</lastName><created>2018-05-10T09:41:39.000Z</created><event>G</event></person>'+
' <person><firstName>Robert</firstName><lastName>Doe</lastName><created>2016-05-23T09:41:39.000Z</created><event>H</event></person>'+
'</personDatabase>'
def people = new XmlSlurper().parseText(stringXML)
people.person.findAll { p ->
p.event.toString().equals('H')
}.each { p ->
println p.created
}
This results in:
Adapt it to your needs.
Live: https://groovy-playground.appspot.com/?_sm_au_=iVVR2FSD4MsqWj30