Comparing a value(userAccountId) from the two responses if UserAccountid matches then print first response of that AccountId

33 Views Asked by At

I have two responses

Response1 = [{ "Cash": 49004.65, "enerabielus": "INDIVIDUAL", "elous":true,"UserAccountID": 4198258}] And Response2 = [[{"userAccountId": 2869483, "details": [ {"state": "VERIFIED", "type": "PERSHING" }, { "state": "BLOCKED", "type": "PCB" } ] }, { "userAccountId": 2870666, "details": [ { "state": "VERIFIED", "type": "Pershing" }, { "state": "BLOCKED", "type": "PCB"}] I

this is sample response only but it might have more values in Response1 and Response2 length is also not same. I want to first match userAccountId from both the responses if the userAccountID matches then I need to print response 1. In karate how can we do that?

Response1 = my first response

response2 = my second response

* def userAccounids2 = karate.map(response2, function(item) { return item.userAccountId})

*def matchedresponse = null

*karate.forEach(Response1, function(item) {

if (userAccountId2.contains(item.userAccountId)) {

matchedResponse =item;

}})

*print matchedResponse

0

There are 0 best solutions below