If condition comparing response value with the Collection variable in an array

Your question may already have an answer on the community forum. Please search for related topics, and then read through the guidelines before creating a new topic.

Here’s an outline with best practices for making your inquiry.
My Question:

  1. I want to assert “FP”: “FOP2”. - Completed
  2. And If 1st step is success. I want to Assert “SMO”: false, - Completed
  3. And also I need to Assert SP.name.FOP2 and its corresponding Exam.“Marksguid”: “f778dd51-d401-42ca-a5ea-4920db5708b2”, - Completed
  4. If I’m comparing if(item.FP) with the collection variable (if FOP2 (value) is in a collection variable)

This is the API JSON Response

[{
“FP”: “DAV1”,
“SMO”: false,
“SP”: [{
“name”: “FOP1”,
“Exam”: [{
“Marksguid”: “a02dac4f-630f-4ed0-aa54-8c7044b71f2f”,
“apiUrl”: “test1”,
“interval”: 65,
“schemaVersion”: “1.2”,
“authenticationType”: “Basic”
}]
}]
}, {
“FP”: “FOP10”,
“SMO”: false,
“SP”: [{
“name”: “FOP10”,
“Exam”: [{
“Marksguid”: “f778dd51-d401-42ca-a5ea-4920db5708b2”,
“apiUrl”: “test1”,
“interval”: 65,
“schemaVersion”: “1.2”,
“authenticationType”: “Basic”

}]
}]
}]

The below Script is working fine for picking the value one of my friend in this community helped me (Bbahadur).
Now if I’m want to compare if(item.FP) with the collection variable (if FOP2 (value) is in a collection variable).
I ahd FOP2 value in a collection variable now I want to compare if(item.FP==Collectionvariable) I used get collection variable syntax but still it throws undefined

pm.test(‘Assertions’, () => {
var FP_exists; // a variable in which we will save the required FP from response if it exists
_.each(jsonData, (item) => {
if(item.FP==“FOP10”)
pm.expect(item.SMO).to.eql(false)

if(item.FP==“testnorecords”)
FP_exists=item.FP;
})
//after looping through all objets, we check if the required FP value exists or not
pm.test(“testnorecords exists”,()=>{
pm.expect(FP_exists).to.eql(“testnorecords”);
})
})

My question:
The above Script is working fine for picking the value one of my friend in this community helped me (Bbahadur).
Now if I’m want to compare if(item.FP) with the collection variable (if FOP2 (value) is in a collection variable).
I ahd FOP2 value in a collection variable now I want to compare if(item.FP==Collectionvariable) I used get collection variable syntax but still it throws undefined

Details (like screenshots):

How I found the problem:

I’ve already tried: