- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 09:21 AM
Hi All,
In below script i need to get latest date of 'lastEscalatedTS' case number
[{"caseNumber" : "3PR0217912", "firstEscalatedTS" : "2024-02-28T12:33:52Z", "lastEscalatedTS" : "2024-02-28T12:34:44Z"}, {"caseNumber" : "3PR0218796", "firstEscalatedTS" : "2024-03-04T16:27:18Z", "lastEscalatedTS" : "2024-03-04T16:26:45Z"}]
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 02:30 AM
var jsonString= ' [{"caseNumber" : "3PR0217912", "firstEscalatedTS" : "2024-02-28T12:33:52Z", "lastEscalatedTS" : "2024-02-28T12:34:44Z"}, {"caseNumber" : "3PR0218796", "firstEscalatedTS" : "2024-03-04T16:27:18Z", "lastEscalatedTS" : "2024-03-04T16:26:45Z"}]';
var cases = JSON.parse(jsonString);
// Initialize a variable to store the latest date
var latestDate;
// Iterate through the array of objects
for (var i = 0; i < cases.length; i++) {
// Get the 'lastEscalatedTS' value for the current case
var currentLastEscalatedTS = cases[i].lastEscalatedTS;
// If this is the first iteration or the current date is later than the latest date found so far
if (!latestDate || currentLastEscalatedTS > latestDate) {
// Update the latest date to the current date
latestDate = currentLastEscalatedTS;
var casenumber = cases[i].caseNumber;
}
}
// Output the latest date
gs.info('Latest date of lastEscalatedTS: ' + latestDate);
gs.info('Latest date of lastEscalatedTS: ' + casenumber);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 11:07 AM - edited 03-25-2024 11:08 AM
Hi @siva mani kanta ,
To find the latest date of 'lastEscalatedTS' case number from given JSON Formatted String . Please use below script
var jsonString= ' [{"caseNumber" : "3PR0217912", "firstEscalatedTS" : "2024-02-28T12:33:52Z", "lastEscalatedTS" : "2024-02-28T12:34:44Z"}, {"caseNumber" : "3PR0218796", "firstEscalatedTS" : "2024-03-04T16:27:18Z", "lastEscalatedTS" : "2024-03-04T16:26:45Z"}]';
var cases = JSON.parse(jsonString);
// Initialize a variable to store the latest date
var latestDate;
// Iterate through the array of objects
for (var i = 0; i < cases.length; i++) {
// Get the 'lastEscalatedTS' value for the current case
var currentLastEscalatedTS = cases[i].lastEscalatedTS;
// If this is the first iteration or the current date is later than the latest date found so far
if (!latestDate || currentLastEscalatedTS > latestDate) {
// Update the latest date to the current date
latestDate = currentLastEscalatedTS;
}
}
// Output the latest date
gs.info('Latest date of lastEscalatedTS: ' + latestDate);
Please mark Correct if this resolves your issue, and also mark Helpful if you find my response valuable based on its impact.
Regards,
Astik Thombare
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 02:28 AM
HI @Astik Thombare
the above script is fine but i need to get that latest date object i need that casenumber
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 02:30 AM
var jsonString= ' [{"caseNumber" : "3PR0217912", "firstEscalatedTS" : "2024-02-28T12:33:52Z", "lastEscalatedTS" : "2024-02-28T12:34:44Z"}, {"caseNumber" : "3PR0218796", "firstEscalatedTS" : "2024-03-04T16:27:18Z", "lastEscalatedTS" : "2024-03-04T16:26:45Z"}]';
var cases = JSON.parse(jsonString);
// Initialize a variable to store the latest date
var latestDate;
// Iterate through the array of objects
for (var i = 0; i < cases.length; i++) {
// Get the 'lastEscalatedTS' value for the current case
var currentLastEscalatedTS = cases[i].lastEscalatedTS;
// If this is the first iteration or the current date is later than the latest date found so far
if (!latestDate || currentLastEscalatedTS > latestDate) {
// Update the latest date to the current date
latestDate = currentLastEscalatedTS;
var casenumber = cases[i].caseNumber;
}
}
// Output the latest date
gs.info('Latest date of lastEscalatedTS: ' + latestDate);
gs.info('Latest date of lastEscalatedTS: ' + casenumber);