var jsonData = pm.response.json();
let serviceName = pm.iterationData.get(“Service”); //console.log(serviceName);
var id = jsonData[‘_embedded’][‘doc:solutionDefinitions’].find(item => item.name === serviceName).id; //console.log(id);
pm.environment.set(“solutionDefinitionID”, id);
in above request , i am sending data from csv file from “Service” as column . when i am printing data after reading , able to get data , but while using it in find function its not working . same code is working with stand alone data ( without using itertaion ) … that means find method also working alone
In the find, you have serviceName).id; which would indicate that its an object? With an “id” key in it. Is the ID contained in your CSV file? (Can you provide a screenshot of the CSV file?).
Does the following actually return anything. I would expect it to be undefined as I can’t see it being initialised anywhere in the script.
console.log(id);
If the ID is part of the service name, then it should be.
I’m wondering if you need another set of brackets in there.
var id = (jsonData[‘_embedded’][‘doc:solutionDefinitions’].find(item => item.name === serviceName)).id;
However, as you say its working without the iterationData, I’m assuming that the find is actually ok.
Although I would probably break it down into two lines for troubleshooting.
let search = jsonData["_embedded’"["doc:solutionDefinitions"].find(item => item.name === serviceName); // special characters so using [] instead of dot notation.
console.log(search);
let id = search.id;
console.log(id);
You can also reference variables from the CSV file using the special data variable.
let serviceName = data.Service
Finally, does the console log for the serviceName work with the iterationData (or is that failing).
If you copy and paste your example response as text, I can reproduce this my end.
var jsonData = pm.response.json();
//var serviceName = “Rama Mohan”;
let serviceName = pm.iterationData.get(“Service”);
console.log(serviceName);
var sol = jsonData[‘_embedded’][‘doc:solutionDefinitions’]
var result = sol.find(obj => {
// Returns the object where the given property has some value
return obj.name === serviceName
})
console.log(result.id)
for same object want to find “id” property by using "name ".
const jsonData = pm.response.json()
let serviceName = data.Service // data will be an object with the current iteration data
// let serviceName = "Dev Test"
console.log(serviceName); // "Dev Test"
let search = jsonData["_embedded"]["doc:solutionDefinitions"].find(item => item.name === serviceName);
console.log(search);
let id = search.id;
console.log(id); // 1107255b