I am creating an employee reimbursement application with Java Servlets, Ajax, and Postgres Database. The server / Java side of the application works well. The problem is with vanilla JavaScript / Ajax via the Date() function in JavaScript.
When the employee creates a ticket, the date of submission gets set correctly, but the resolve date is set to null because there is no guarantee when the manager will get around to approving the request. At first the new ticket has a status of pending until the manager approves or denies the request, which will correspond to the resolve date.
Here is the problem the resolve date in the database has null values. The JavaScript Date() function does not know how to interpret a null value. Depending on weather I use new Date( the date inside the database).toDateString() or Date(the date inside the database), it will display all null values, or the epoch date (January 1, 1970), or today’s date for each ticket in the database, even with a valid date in the resolve date field inside the database.
I was willing to accept the epoch date but this date still shows with a valid date in the database’s resolve date field.
Here is the Ajax response: { `var JavaTicketData = xhttp.responseText; var andy = JSON.parse(JavaTicketData); var data = " ";
for(let i = 0; i < andy.length; i++)
{
data += "<tr class = 'suckerFish'>" +
"<td class='sonOfSuckerFish'>" + andy[i].ticketNumber + "</td> " +
"<td class='sonOfSuckerFish'>" + andy[i].ticketsDescription + "</td> " +
"<td class='sonOfSuckerFish'>" + andy[i].ticketsStatus + "</td> " +
"<td class='sonOfSuckerFish'>" + andy[i].reimbursementAmount + "</td> "+
"<td class='sonOfSuckerFish'>" + new
Date(andy[i].dateSubmitted ).toDateString() + "</td> " +
"<td class='sonOfSuckerFish'>" +
Date(andy[i].dateResolved).toDateString() + "</td> " +
"<td class='sonOfSuckerFish'>" + andy[i].reimbursementType + "</td> " +
"<td class='sonOfSuckerFish'>" + andy[i].employeeID + "</td></tr>";
}
let Outter = "<table id = 'AndreTable'><tr><th>Ticket Number</th><th>Ticket Description</th><th>Ticket Status</th>"
+ "<th>Reimbursement Amount </th><th>Date Submitted </th><th>Date Resolved </th> <th>Reimbursement Type </th>"
+ "<th> Employee ID </th> </tr>";
document.getElementById("ManagerDisplay").innerHTML = Outter + data + "</table>";`
} Note: The datatype for my date fields inside the database are timestamps
When I use new Date(andy[i].dateResolved), it displays
When I use new Date(andy[i].dateResolved).toDateString()