In UI page code doesn't work different instance environments

Anish9515
Tera Contributor

UI Page code works on my PDI, but doesn't work in my company instance and I don't receive expected output. Can anyone help me?

@Amit Gujarathi @Ankur Bawiskar

9 REPLIES 9

By using the UI action button, particular role users can change into past dates for change requests, i.e. planned start and end dates  

 

Suresh47_0-1701525617504.png

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Anish9515 

what's your business requirement to use UI page?

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

When user clicks ui action button inside UI pages fields  created are there i.e , Planned start date , Planned end date and reason.
 particular role users can change into past dates for change requests, i.e. planned start and end dates .

it's working on properly my PDI but doesn't work on my company instance

How to fix this one

Suresh47_0-1701587092889.png

 

Suresh47_1-1701587145680.png

 

Amit Gujarathi
Giga Sage
Giga Sage

HI @Anish9515 ,
I trust you are doing great.
Please find the updated code. :

function onSubmit() {
    var startDateInput = document.getElementById("date");
    var endDateInput = document.getElementById("date1");
    var errorElement = document.getElementById("error-message");

    var startDateStr = startDateInput.value;
    alert("The start date is " + startDateStr);
    if (startDateStr === '') {
        errorElement.textContent = "Please select the planned start date";
        errorElement.style.display = "block";
        return false;
    }

    var endDateStr = endDateInput.value;
    alert("The end date is " + endDateStr);
    if (endDateStr === '') {
        errorElement.textContent = "Please select the planned end date";
        errorElement.style.display = "block";
        return false;
    }

    var comments = document.getElementById("info").value.trim();
    if (comments === "") {
        errorElement.textContent = "Reason to set the date in the past";
        errorElement.style.display = "block";
        return false;
    }

    // Convert user date strings to Date objects for comparison
    var startDate = new Date(startDateStr);
    var endDate = new Date(endDateStr);
    var currentDate = new Date(); // Current date and time

    // Formatting the current date to match the user date format (if necessary)
    // Assuming g_user_date_format includes both date and time
    var currentDateFormatted = formatDate(currentDate, g_user_date_time_format);
    alert("The current date is " + currentDateFormatted);

    // Comparing dates
    if(startDate > currentDate) {
        errorElement.textContent = "The Planned start date cannot be in the future";
        errorElement.style.display = "block";
        return false;
    }
    if(endDate < startDate) {
        errorElement.textContent = "Planned end date must be after planned start date";
        errorElement.style.display = "block";
        return false;
    }
    return true;
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



My adjustment code is working fine in my PDI
But same code doesn't work on my company instances
I guess "current date" is an issue