ContributionsMost RecentMost LikesSolutionsRe: Get attribute value to variable I propably was able to fix it by myself by changing from XmlParser() to XmlSlurper() Get attribute value to variable In groovy script I have following log.info(blabla) //prints out INFO:XMLRESPONSE[attributes={}; value=[000XXXAAACCC]] and when I try log.info(blabla.value) //prints out empty INFO:[] How can I get just 000XXXAAACCC added to variable? Re: Assert = false and log.info to the console Actually it's not giving error. It's just no executed. If I comment assert out, I will get log.info to the console ====================================================== def firstName1 = (json.nameList[0].firstName) // take Name if ( firstName1 != null ) { // firstName1 has a value. It's not null {assert true} log.info("firstName = " + firstName1) // print to console } else { log.info("firstName = " + firstName1) // { assert false} } ====================================================== Then I will see output Fri Feb 17 15:01:15 CET 2023:INFO:firstName = null Assert = false and log.info to the console When firstName is null I would like to assert false and print log.info but in "else" part I cannot print log.info to console. Any thoughts? Following piece of script. ====================================================== def firstName1 = (json.nameList[0].firstName) // take Name if ( firstName1 != null ) { // firstName1 has a value. It's not null {assert true} log.info("firstName = " + firstName1) // print to console } else { log.info("firstName = " + firstName1) { assert false} } SolvedRe: Getting elements from json list to varable Actually works. This line json.list[0].status helps. I am getting now values Getting elements from json list to varable Let's say I have following json response list stored in "response" variable import groovy.json.JsonSlurper def response = context.expand( '${GetResponse#response}' ).toString() // get response data to string log.info(response) // print the data list {"list": [{"status": "ACTIVE", "Number": 123, "Version": "1.12"}]} Now I want to get e.g. status and put it to variable "currentStatus" and Number to "currentNumber". So how to do it? I tried few ways with JsonSlurper() but always getting "null" value SolvedRe: Try-Catch "No such property: carried for the class:" error Ok, works now. I had a little error in my script. Re: Try-Catch "No such property: carried for the class:" error Actually I already tried it once and " startup failed: Script4.groovy: 28: The current scope already contains a variable of the name carried @ line 28, column 7. def carried =" so it doesn't let me define twice. Try-Catch "No such property: carried for the class:" error Following piece of groovy: import groovy.json.JsonSlurper def response = context.expand( '${GetAccumulated#response}' ).toString() log.info(response) // This is OK. List is printed to the console def slurper = new JsonSlurper() def json = slurper.parseText response log.info(json) // OK and printed to the console // then I try to catch exception try { def carried = json.carriedFromPrevious // taking carriedFromPrevious from the list log.info("carriedFromPrevious = " + carried) // looks OK, so correct number is printed to the console } catch (Exception ex) { log.info("Respond not a number") log.info(ex) } log.info("carriedFromPrevious = " + carried) // when trying to print it again comes an error "No such property: carried for the class:" // Now I am wondering what will happen to "carried" variable during try-catch operation? Why I cannot print it again? Do I have to specify it somewhere again? SolvedRe: Groovy: Redirect log.info output from console to the file Yep, that's what I thought and it requires Admin rights