-1

I would like to get the value of the "currentApproversStr:" based on the condition "status":"Ready for Review" from the below JSON Response body of a HTTP sampler and pass to following HTTP sampler.

I tried the below but it's not working

  1. Names of created variables: currentApproversStr
  2. JSON Path expressions: $.[?((@.currentApproversStr == "Validation, Civa" || @.currentApproversStr == "Validation, Darla" || @.currentApproversStr == "Validation, Bittl" || @.currentApproversStr == "Validation, Cha" || @.currentApproversStr == "Validation, Barnett" ) && @.status== "Ready for Review")]
  3. Match No: -1 OR 1

But Dummy Sampler returns the Results

We can't guarantee the order of the "timecardId" block with the "status":"Ready for Review" i.e some times 2 nd place, some times last. In this it's 2nd block. So not sure Match No: what should i give enter image description here

[
  {
    "timecardId": 170803,
    "entryHeaderId": "db9341a9-32e8-4d45-a858-a88b75a42cef",
    "startsOn": "2021-10-24T00:00:00",
    "endsOn": "2021-10-30T00:00:00",
    "worksightStatus": "SignedOff",
    "projectId": 1977,
    "userId": 60874,
    "status": "Submitted for Approval",
    "batchId": 39814,
    "emergencyType": "",
    "htgDealMemoId": "0d0ff42b-5c4b-4695-b527-34dfc64585e5",
    "unionId": "1c77c660-28fc-4e40-b557-132f3da39597",
    "currentApproversStr": "Perf, PA",
    "commentStr": "",
    "commentUserName": "",
    "commentCreatedAt": "1900-01-01T00:00:00",
    "occupationCode": "TECHNICIAN",
    "activeApprovalFlowId": 166669,
    "isAllowanceOnly": false,
    "departmentId": null,
    "datePosted": null
  },
  {
    "timecardId": 170807,
    "entryHeaderId": "c9809446-b01f-4f42-add6-9b441c3d0114",
    "startsOn": "2021-10-17T00:00:00",
    "endsOn": "2021-10-23T00:00:00",
    "worksightStatus": "Outstanding",
    "projectId": 1977,
    "userId": 60874,
    "status": "Ready for Review",
    "batchId": 39815,
    "emergencyType": "",
    "htgDealMemoId": "0d0ff42b-5c4b-4695-b527-34dfc64585e5",
    "unionId": "1c77c660-28fc-4e40-b557-132f3da39597",
    "currentApproversStr": "Validation, Civa",
    "commentStr": "",
    "commentUserName": "",
    "commentCreatedAt": "1900-01-01T00:00:00",
    "occupationCode": "TECHNICIAN",
    "activeApprovalFlowId": 166674,
    "isAllowanceOnly": false,
    "departmentId": null,
    "datePosted": null
  },
  {
    "timecardId": 170802,
    "entryHeaderId": "db9341a9-32e8-4d45-a858-a88b75a42cef",
    "startsOn": "2021-10-24T00:00:00",
    "endsOn": "2021-10-30T00:00:00",
    "worksightStatus": "SignedOff",
    "projectId": 1977,
    "userId": 60874,
    "status": "Submitted for Approval",
    "batchId": 39814,
    "emergencyType": "",
    "htgDealMemoId": "0d0ff42b-5c4b-4695-b527-34dfc64585e5",
    "unionId": "1c77c660-28fc-4e40-b557-132f3da39597",
    "currentApproversStr": "Perf, PA",
    "commentStr": "",
    "commentUserName": "",
    "commentCreatedAt": "1900-01-01T00:00:00",
    "occupationCode": "TECHNICIAN",
    "activeApprovalFlowId": 166669,
    "isAllowanceOnly": false,
    "departmentId": null,
    "datePosted": null
  }
]

enter image description here

enter image description here enter image description here

rpagadala
  • 796
  • 2
  • 15
  • 31

2 Answers2

0

"Match No" works as follows: if your query returns more than 1 result:

  1. 0 - returns random result

  2. -1 - returns ALL results in form of:

    • currentApproversStr_1 - first match
    • currentApproversStr_2 - second match
    • etc.
    • currentApproversStr_matchNr - total number of matches
  3. any positive integer - returns the given match

It applies not only to JSON Extractor but to all other JMeter PostProcessors which extract values from responses.

You can see generated JMeter Variables using Debug Sampler and View Results Tree listener combination:

enter image description here

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
0

PROBLEM: The reason is that you misunderstand the way JSON extractor works. This feature allows you extract many variables in one setting, but number of Names of created variables = number of JSON Path expressions = number of Default Values.

For example, you want to extract 2 variables:

  • Names of created variables: var_name_1; var_name_2

  • JSON Path expressions: json_expression_1; json_expression_2

  • Default Values: default_1; default_2

(Note: remember using semicolon (;) to separate values)

But you set 1 Variable, 1 json expression with MANY default values --> mismatch.

SOLUTION: You can setup like this:

Names of created variables: currentApproversStr
JSON Path expressions: $.[?(@.status== "Ready for Review")].currentApproversStr
Match No: -1
Default Values: NOT_FOUND

Result:

currentApproversStr_1=Validation, Civa
currentApproversStr_matchNr=1
lucas-nguyen-17
  • 5,516
  • 2
  • 9
  • 20
  • It's returns the results, but not replacing the value in the following request. Not able to figured it out what went wrong. See the attached screenshots – rpagadala Oct 17 '21 at 19:58
  • @rpagadala If `Match No: -1` and only one match --> var_name will be `currentApproversStr_1`. You can change `Match No: -1` --> `Match No: 1`, then get the var_name is `currentApproversStr` – lucas-nguyen-17 Oct 18 '21 at 01:45
  • @lucsnaguyen It worked! Thank you so much! – rpagadala Oct 21 '21 at 20:10