How to get Json value from response when there is different array with same value

Hi All, in the below mentioned response we have different array which same value pattern, i need to pass the the “processInstanceId” value from array which has " freitext == submission" to next request. i need a test script and pre requisite script for next resquest. need immediate help on this automation scenario

[
{

    "processInstanceId": "c0afa9cd-120b-11eb-ae9a-0a580a5e1be9",

    "processDefinitionId": "6d2a164d-0261-11eb-ae9a-0a580a5e1be9",

    "processDefinitionName": "Policy Policierung Folgeverarbeitung",

    "invoiceNumber": null,

    "amount": null,

    "startTime": "2020-10-19T15:05:25.161+0200",

    "endTime": "2020-10-19T15:05:37.119+0200",

    "durationInMillis": 11958,

“businessKey”: null,

    "versicherungsnummer": "56000113141",

    "partnernummer": "XUKTDM",

    "organisationsnummer": null,

    "schadennummer": null,

    "freitext": "Cancelation, 17aef182-d885-40d1-af8f-fad9b31ac465",

    "zielgruppe": null,

    "sender": "GWPC",

    "eingangskanal": null,

    "callbackid": "17aef182-d885-40d1-af8f-fad9b31ac465",

   "status": "COMPLETED"

}
{
“processInstanceId”: “386dc8d9-1204-11eb-ae9a-0a580a5e1be9”,

    "processDefinitionId": "6d2a164d-0261-11eb-ae9a-0a580a5e1be9",

    "processDefinitionName": "Policy Policierung Folgeverarbeitung",

    "startTime": "2020-10-19T14:11:30.082+0200",

    "endTime": "2020-10-19T14:11:46.758+0200",

    "durationInMillis": 16676,

“versicherungsnummer”: “56000113141”,

    "partnernummer": "XUKTDM",

    "organisationsnummer": null,

    "schadennummer": null,

    "freitext": "Submission, 80b856c6-8da8-4e4f-86da-0f65bc1981c2",

   
    "callbackid": "80b856c6-8da8-4e4f-86da-0f65bc1981c2",

    "kontaktid": "25cef3aa-2502-4c7e-81df-579864e95b36",

   

    "status": "COMPLETED"

}
]

Hi @jayaveljays
Welcome to the community!

Please refer to this for parsing response response body and getting a value.

In your case you can simply write a for loop through the array of json objects inside the array and if freitext contains Submission, then find the value of processInstanceId and save it to postman environment variables (for example).

var response = pm.response.json();
for (var i=0; i < response.length; i++) {
 if(response[i].freitext.includes("Submission")) {
       pm.envinronment.set("ID", response[i].processInstanceId);
       break;
   }
}

Thank you so much @jeevananthank, I really appreciate your work. now i made it working.
Thanks once again for your helping hand

1 Like