Ask a Question

Compare response to table values


Compare response to table values

I have a response(i have multiple such entries copied only one.) like below and I have a table that I need to compare it against.


"Items": [
"EmployeeId": "1",
"CompanyId": "1",
"FirstName": "SPENCER",
"LastName": "LIN"
"Status": {
"Code": "A",
"Description": "Active"
"BenefitClass": null,
"SupervisorId": null,
"SupervisorFirstName": null,
"SupervisorLastName": null,
"CostCenters": [
"Code": "01",
"Description": "Corporate"


I was able to print the results of the value in DB, like below:

/*****************************************this is the employeeId returned from DB.**************************************/
def returntripDB = getEmployeeFromDB(db,jsonRes)

returned DB value[[Id:1], [Id:113], [Id:129], [Id:130], [Id:131], [Id:134], [Id:136], [Id:140], [Id:143]]

public def getEmployeeFromDB(def database,jsonRes)
def query = "SELECT Id FROM [mydb].[mydb].[etable] order by etableid asc"
// "QUERY for all employee id only "+query
return database.rows(query)



I want to iterate through the reponse and compare the values to the DB. How can i do this?


that was a helpful post thanks Rao. 

this is what i have so far 



/******* Create a Array and add all employeeIds from reponse*******/

def responseList = []

jsonRes.Items.EmployeeId.each {

    responseList.add(it.value) //'it' is the name of the default iterator created by the .each()

  // "all the employee ids in reponse in array"+responseList



/******* Create a Array and add all employeeIds from Database*******/

def empIdFromDB = []

returntripDB.each {


  // "all the employee ids in reponse in array"+empIdFromDB



//sorting the Data before checking for equality

def a = responseList.sort() "all the employee ids in reponse in array"+a

def b = empIdFromDB.sort() "all the employee ids in DB in array"+b


BUT the result am getting is not what i want: below is the result



all the employee ids in reponse in array[29, 2, 6, 1, 4, 3, 5]
all the employee ids in DB in array[ , ,, , ], 6, ,, ,, ,, 4, 9, 5, , , 2, [, , , ,, ,, 2, 3, 1]


Why is it not sorting the data.Also why is the DB results all screwed up?.



It appears that db is returning results as list some times. So it is adding list when you add, inside of a list. Please check it.


Iam sorry but iam seeking answer since am not a groovy expert. All i know is i am capturing results in a array.


please help.

With given details, it is difficult to provide exact solution that works with your data.
You need to check(can use instanceof List) if empIdFromDB is List/Array, then again do loop then add value.


what information do you need ?.

Showing results for 
Search instead for 
Did you mean: