0

I'm using the find function in postman tests to save environment variables, the find function works great when I'm looking for a variable, But I cannot get it to work when looking for variables inside an object

My payload looks something like this

{
    "name": "product1",
    "state": {
        "DefinitionId": "productcard",
        "Id": "32919b8c-984e-46c3-933d-51d3c621d4cf"
    },
    "status": "Done"
},
{
    "name": "product2",
    "state": {
        "DefinitionId": "productaccount",
        "Id": "4999b8c-984e-46c3-933d-55d3c621d4cf"
    },
    "status": "NotDone"
},

with the _find function I can find variables through the name variable

 var steps = _.find(resBody, { 
        name: "product1", 
    })
    pm.environment.set(steps.name, steps.state.Id);

But what If I want to search by DefinitionId? I have tried stuffs like this

 _.find(resBody, { 
      name.state: "product1", 
      }) <--did not work

 _.find(resBody.state, { 
      name.state: "product1", 
      }) <--did not work [returns object object]

Thanks in advance.

1 Answer 1

1

This should return the an object by a DefinitionId search, if that's what you mean?

var result = resBody.find(x => x.state.DefinitionId === "productaccount");

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.