Populate date and time depends on choice

charitha ts
Tera Contributor

I am working for Record Producer (RP table is HR payroll case) for workday integration for HRSD 

 

1. variable is What date/dates is this request for? and logic is If selected date is within 2 weeks of today's date and the choice is Vacation. Then display a pop-up message. Vacation requests must be at least 2 weeks in advance and will require additional approvals if you wish to proceed. felid type is Date and time.

 

2. variable is Exception Reason variable type is multiline text and logic is Display if If selected date is within 2 weeks of today's date and the choice is Vacation.

 

Can anyone help in code please 

 

Thanks in adavnce

Charitha TS

 

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@charitha ts You can create an onChange client script on both of your variables and use the following code.

 

 

// Get today's date
    var today = new Date();
    today.setHours(0, 0, 0, 0); // Set time to midnight for accurate comparison

    // Parse the selected date
    var selectedDate = new Date(newValue);

    // Calculate two weeks from today's date
    var twoWeeksLater = new Date(today);
    twoWeeksLater.setDate(today.getDate() + 14);

    // Check if selected date is within two weeks
    if (selectedDate >= today && selectedDate <= twoWeeksLater) {
        g_form.addInfoMessage('The selected date is within two weeks of today.');
    } else {
        g_form.clearMessages(); // Clear messages if no longer in the two-week window
    }

 

 

Update the logic to show message/display exception reason field.

 

Hope this helps.

View solution in original post

2 REPLIES 2

Sandeep Rajput
Tera Patron
Tera Patron

@charitha ts You can create an onChange client script on both of your variables and use the following code.

 

 

// Get today's date
    var today = new Date();
    today.setHours(0, 0, 0, 0); // Set time to midnight for accurate comparison

    // Parse the selected date
    var selectedDate = new Date(newValue);

    // Calculate two weeks from today's date
    var twoWeeksLater = new Date(today);
    twoWeeksLater.setDate(today.getDate() + 14);

    // Check if selected date is within two weeks
    if (selectedDate >= today && selectedDate <= twoWeeksLater) {
        g_form.addInfoMessage('The selected date is within two weeks of today.');
    } else {
        g_form.clearMessages(); // Clear messages if no longer in the two-week window
    }

 

 

Update the logic to show message/display exception reason field.

 

Hope this helps.

First variable is working and second variable i will check and update you