22 Aug 2024 05:45 PM - last edited on 23 Aug 2024 12:16 PM by MaciejNeumann
23 Aug 2024 08:33 AM
Hello Nares,
I used the Date.parse that you sent and is working for me inside a JavaScript code execution:
Can you send the code that you are using inside Dynatrace so I can help you more?
23 Aug 2024 11:46 AM
Hi Jaume,
Sample code and payload given below,
responseBody = "{\"data\":[{\"jobNumber\":1000001207847,\"status\":\"S\",\"project\":\"ProdDT\",\"userName\":\"mftstageadmineu\",\"endTime\":\"8/23/24 10:37:38 AM\"},{\"jobNumber\":1000001207846,\"status\":\"S\",\"project\":\"ProdDT\",\"userName\":\"mftstageadmineu\",\"endTime\":\"8/23/24 10:37:35 AM\"},{\"jobNumber\":1000001207845,\"status\":\"S\",\"project\":\"AzureStage\",\"userName\":\"mftprojectlaunch\",\"endTime\":\"8/23/24 10:37:32 AM\"},{\"jobNumber\":1000001207844,\"status\":\"S\",\"project\":\"PingProd\",\"userName\":\"mftstageadmineu\",\"endTime\":\"8/23/24 10:37:35 AM\"},{\"jobNumber\":1000001207843,\"status\":\"S\",\"project\":\"PingProd\",\"userName\":\"mftstageadmineu\",\"endTime\":\"8/23/24 10:37:38 AM\"}]}"
if (response.getStatusCode() != 200) {
api.fail("HTTP error: " + response.getStatusCode());
}
var responseBody = response.getResponseBody();
var jsonData = JSON.parse(responseBody);
for (j = 0; j < (jsonData.data).length; j++) {
var ProdDTJobTime = (jsonData.data)[j].endTime + ' GMT';
var ProdDTJobResult = Date.now() - Date.parse(ProdDTJobTime) < 86400000 ? "triggered now" : "triggered later";
if ((jsonData.data)[j].project === "ProdDT") {
if (ProdDTJobResult === "triggered later") {
api.fail("New job was not triggered for " + (jsonData.data)[j].project + " Last triggered time in UTC was : " + (jsonData.data)[j].endTime);
break;
}
api.setValue("ProdDT", (jsonData.data)[j].jobNumber);
api.info((jsonData.data)[j].jobNumber);
break;
}
}