0

I have a Json payload i.e.

{
    "Numbers": [
        0
    ],
    "title": "string",
    "Ids": [
        0, 1, 2
    ],
    "group": 0
}

and I am hitting a http call to get collection of records for all customers present in DB i.e.

{
    "details": [{
            "detailId": 0,
            "Id": 0,
            "name": "string",
            "place": "string",
            "country": "string",
            "bloodgroup": "string",
            "area": "string"
        },
        {
            "detailId": 0,
            "Id": 1,
            "name": "string",
            "place": "string",
            "country": "string",
            "bloodgroup": "string",
            "area": "string"
        }
    ]
}

Now I want to filter and extract the data for those Ids for which I am getting in Request payload in Ids field and match them in collection response payload.

ID field is common in Request payload and in Response payload

Please help me on this.

fabrik
  • 14,094
  • 8
  • 55
  • 71
shruti
  • 1

1 Answers1

0

Let's assume you're storing the first payload in a variable called flowVars.ids. You want to use the contains method, which works returns true if the value you're checking is contained in the array, otherwise it returns false. Here's a couple examples:

// Returns true
[1,2,3,4,5] contains 5

// Returns false
[1,2,3,4,5] contains "Hello"

So you could structure your filter like this (assuming Mule 3.x and DataWeave 1.0):

%dw 1.0
%output application/java

%var ids = flowVars.ids.Ids
---
payload.details filter (ids contains $.Id)
jerney
  • 2,187
  • 1
  • 19
  • 31
  • I got your point but my requirement is different from which you have explained: I am getting a list of ids in Request payload and I have stored it in a variable because there is a http call in which I am getting details and my whole payload is getting changed after that so, in transformer what I want to do is I want to extract all the details for a particular id which I am getting in my request. I.e for every id I have a detail block which I want as a collection in my payload after transformation. Hope you got my point – shruti Sep 14 '18 at 06:44
  • Hmm, no I still don't understand, then... if you could post your XML and what you're expecting as a result, I could probably be more helpful. – jerney Sep 15 '18 at 13:44