Forum Discussion

Premier2k's avatar
Occasional Contributor
9 years ago

Looping through a resultset

Hi all,


I'm trying to loop through a result set and add the results to a map, I have done this already with some JSON output and I'm trying to do the same for the database resultset but it's only returning the first row in the results. 


This is what I have so far;


def groovyUtils = new
import groovy.json.*

def responseJSON = testRunner.testCase.testSteps["Retrieve case data from GW"].testRequest.response.responseContent

def response = new JsonSlurper().parseText(responseJSON)
def responseXML = new XmlHolder (testRunner.testCase.testSteps["Retrieve household data from staging"].testRequest.response.responseContent)

def gatewayMap = [
	(response.householdExpenditure.expenditureType.each{}) : response.householdExpenditure.expenditureAmount.each{}

def stagingMap = [
	(responseXML.getNodeValue("//Results/ResultSet/Row/EXPENDITURETYPE").each{}) : Math.round(responseXML.getNodeValue("//Results/ResultSet/Row/EXPENDITUREAMOUNT").each{}.toFloat())
] gatewayMap stagingMap

The output from the log shows only the first row, it doesn't seem to be iterating through the rows. I believe I'm missing something after /Row[something here?]/EXPENDITURETYPE but I'm not sure what?

The gatewayMap works as expected, it's just the stagingMap that's causing me problems.





12 Replies

  • nmrao's avatar
    Champion Level 3
    Can you show the sample response and which data you are trying to retrieve?
    • Premier2k's avatar
      Occasional Contributor

      Sure, I've attached the response I'm getting back from my DB call.

      • nmrao's avatar
        Champion Level 3
        But this is not json in the first place.

        So what data you want ?