Forum Discussion

chriscropley's avatar
chriscropley
Occasional Contributor
3 years ago
Solved

How to retrieve Node Tree when child value matches text

Dear Smartbear community,   it has been a while since I have been at the coal face however I have searched far and wide for a response yet I can't quite find a solution to my problem.  I hope someo...
  • chriscropley's avatar
    3 years ago

    Thanks to some valuable contributions from other sites, I managed to find a solution.  It was fairly easy in the end stiching some ideas from those posts.  I have put it here in case anyone would like to make use of it.

     

    import groovy.util.*
    import java.text.SimpleDateFormat

    def sdfDateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss")

    //Parse XML content in the response
    def completedResponse = context.expand( '${ListCompletedStreams#Response}' )
    def parsedcompletedResponse = new XmlSlurper().parseText(completedResponse)

    //Loop over each Job Entry
    parsedcompletedResponse.jobs.jobEntry.each { jobEntry ->

    //Loop over every steo entry and pull out only those steps that fail. Find the parent Job Name and other parent properties.
    jobEntry.steps.stepEntry.each { stepEntry ->
    if (stepEntry.stepState.text() == "FAILED" ) {

    def strJobEntryRunDate = Date.parse("yyyy-MM-dd'T'HH:mm:ss", "${jobEntry.runDate.text()}")
    log.info "\tJob Stream : ${jobEntry.name.text()} starting at " + sdfDateFormat.format(strJobEntryRunDate) + " has a failed Job Step."
    log.info "\tJob Step: ${stepEntry.stepName.text()} failed after ${jobEntry.runDuration.text()} minutes."
    }
    }
    }


    return null