Support Questions

Find answers, ask questions, and share your expertise

How can I write EcmaScript for this case.

avatar
Explorer

I have this data saved in an attribute lets say "Data" .I have to Match this "Your_Name" present in this Data with some Field(mentioned below) which will be called after API.

[
  {
    "admin": "A1",
    "Your_Name": "Lily",
    "Reason1": "Shot"  
}
]

 

Now, This is the data which will get after API call in InvokeHttp processor, I have stored it in an "ResponseData" attribute using ExtractText.

I have to match Data's "Your_Name" with ResponseData's "Name", if both of these matches we will send the respectives "nameId" in some outputstream variable or something so that it can go ahead as an output(the nameId only of the Name which matched with Your_Name).

 

[ {
  "Name" : "Ivor",
  "Speciality" : [ {
    "nameId" : "611",
    "SId" : "2"
  } ]
}, {
  "Name" : "Philip",
  "Speciality" : [ {
    "nameId" : "980",
    "SId" : "12"
  } ]
}, {
  "Name" : "Adams",
  "Speciality" : [ {
    "nameId" : "611",
    "SId" : "2"
  } ]
},
{
  "Name" : "Lily",
  "Speciality" : [ {
    "nameId" : "618",
    "SId" : "20"
  } ]
}
]

Two of the Name (here Ivor and Adams) can have the same nameID, So we have to match Name and send its nameId only. I want to write ECMA script for this.

2 REPLIES 2

avatar

@anony I believe your solution is to put/keep Response Data as flowfile content.   Then you can do QueryRecord or PartitionRecord to iterate through each "name" object in the Response Data array.   Then downstream you are able to use EvalateJsonPath to get the json object values into attributes or flowfile content.  For example name= $.name, nameID = $.Speciality[0].nameId, etc

avatar
Super Collaborator

Does it need to be ECMA? I can probably whip something up tomorrow using Groovy.