cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

JSON Response - limit search top 20lines only- HTTP Monitor script

shahrukh_niazi
Visitor

We have a swagger API which outputs a JSON response that has status detail about the execution of our batchjob. 

 

In my post execution script of HTTPMonitor of Dynatrace synthetics, I have this logic

 

responseObject = JSON.parse(response.getResponseBody());

responseObject.runs.forEach(x => {

    if (x.success != true) {

        api.fail(x.id + " failed");

    }

});

 

Batch jobs runs once a day. Our swagger JSON response has status details of last 50executions in the JSON body. I'm only interested in the 0 response - which has the status info of basically today's execution & ignore all the rest.  The above logic works when last 50th execution has no "success :fail" in them 

 

Anyone knows how to limit the search in post execution script of an HTTP Monitor to only look for 0 iteration,  or ,  search first 20lines only & ignore rest of the JSON payload, and if you find "success :true" that means batch job ran successfully. Because first 20 lines has the last execution detail in it..

1 REPLY 1

shahrukh_niazi
Visitor

shahrukh_niazi_0-1617143137089.pngshahrukh_niazi_1-1617143247394.png