Adjust Planned Start date and End Date in the Change Form.

Jayakrishna3
Tera Contributor

I had one requirement like if planned date and end date is either one of black out schedule time then I need to show section tab in change form.

7 REPLIES 7

Jayakrishna3
Tera Contributor
function toUTCDate(dateString) {
    var date = new Date(dateString);
    return new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
}

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    var startDate = toUTCDate('2025-03-24 18:00:00');
    var endDate = toUTCDate('2025-04-10 18:00:00');

    g_form.addInfoMessage("startDate: " + startDate + ", endDate: " + endDate);

    var givenDate = toUTCDate(newValue);

    g_form.addInfoMessage("givenDate: " + givenDate);

    if (givenDate >= startDate && givenDate <= endDate) {
        g_form.addInfoMessage("Inside Planned Start Date Block");
        g_form.setValue('u_bca_freeze', true);
        g_form.setSectionDisplay('bca_freezequestionnaire', true);
    } else {
        g_form.setValue('u_bca_freeze', false);
        g_form.setSectionDisplay('bca_freezequestionnaire', false);
    }
}
//g_form.getControl('start_date').onchange = onChange;

Jayakrishna3
Tera Contributor

I had written this code but the problem here is in four cases, we have to consider.

Note: Black out schedule : March 24th to April 10 2025. 

1)If we choose Planed date : March 3rd 2025 and End Date is Within black out schedule like April 4th. The Section is need to visible.

2)If we choose Planed date and End Date is both within black out schedule. The Section is need to visible.

3)If we choose Planed date : April4th  2025 which one is black schedule date and End Date is like April 16th. The Section is need to visible.

4)If both planned date and end date is out of black schedule period. The section should not visible.

Hi @Jayakrishna3 

You need to use an 'or' condition, then it will work. I’m just thinking out loud here—why not display the section by default and use the conflict status to make it visible? I'm not sure why you're focusing only on dates and creating technical debt.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************