I need to replace All in s3data Emp_Id with the response data’s values(expected output appended), ignore 0 and 1 in response they are not required.
S3data is json data
I can’t use inbuilt function like Object.fromEntries because they are not working in apache nifi execute script. So I have to do this with foreach or with loop so that it can work in nifi.
I tried it but it didn’t work.
var response = {
"status": "success",
"data": [[123, 0], [124, 0], [446, 0], [617, 1], [620, 0], [470 ,1]]
};
var s3Data = {
"Emp_Id": "All",
"Emp_loc": 523,
"Emp_dept": "Management",
"Emp_sub_dept": "Finance",
"Emp_sub_dept2": "Accountant"
};
var result={}
var dataName = s3Data[0].Emp_Id;
response.data.forEach(function(elem, index) {
if(dataName==='All'){
result[0].Emp_Id=elem[0];
}
});
console.log(result);
EXPECTED OUTPUT:
[
{
Emp_Id: 123,
Emp_loc: 523,
Emp_dept: 'Management',
Emp_sub_dept: 'Finance',
Emp_sub_dept2: 'Accountant'
},
{
Emp_Id: 124,
Emp_loc: 523,
Emp_dept: 'Management',
Emp_sub_dept: 'Finance',
Emp_sub_dept2: 'Accountant'
},
{
Emp_Id: 446,
Emp_loc: 523,
Emp_dept: 'Management',
Emp_sub_dept: 'Finance',
Emp_sub_dept2: 'Accountant'
},
{
Emp_Id: 617,
Emp_loc: 523,
Emp_dept: 'Management',
Emp_sub_dept: 'Finance',
Emp_sub_dept2: 'Accountant'
},
{
Emp_Id: 620,
Emp_loc: 523,
Emp_dept: 'Management',
Emp_sub_dept: 'Finance',
Emp_sub_dept2: 'Accountant'
},
{
Emp_Id: 470,
Emp_loc: 523,
Emp_dept: 'Management',
Emp_sub_dept: 'Finance',
Emp_sub_dept2: 'Accountant'
}
]
2
Answers
Here is an object keyed on ID
You can also get the array of values using Object.values