The CreatorCon Call for Content is officially open! Get started here.

Best way to have a list view of dates that are the beginning pay periods

Adam Peterson
Kilo Sage

I am in need of a way to have them select a date but they are only allowed to select the first day of a pay period. So pretty much I need to display every other Sunday. 

Should I use a date field? Should I populate a select box? What's the best way to approach this?

 

Thanks!

1 ACCEPTED SOLUTION

Ok @Adam Peterson 

 

Got it ! Below 👇 script should work 

 

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading || newValue === '') return;

 

    var selectedDate = new Date(newValue);

    var day = selectedDate.getDay(); // 0 = Sunday

 

    if (day !== 0) {

        g_form.showFieldMsg('your_date_field', 'Please select a Sunday.', 'error');

        g_form.setValue('your_date_field', '');

        return;

    }

 

    // Base Sunday: April 6, 2025

    var baseSunday = new Date('2025-04-06');

    var diffTime = selectedDate.getTime() - baseSunday.getTime();

    var diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24));

 

    if (diffDays % 14 !== 0 || diffDays < 0) {

        g_form.showFieldMsg('your_date_field', 'Please select an alternate Sunday starting from April 6, 2025.', 'error');

        g_form.setValue('your_date_field', '');

    } else {

        g_form.hideFieldMsg('your_date_field', true);

    }

}

 

Please change the field names accordingly. 

 

I tried with - 2025-04-13 - didn't accept 

2025-04-27 - didn't accept 

2025-05-18 - accepted. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

View solution in original post

7 REPLIES 7

Shivalika
Mega Sage
Mega Sage

Hello @Adam Peterson 

 

Please use below 👇 on change client script - it would work on birth catalog form and normal form

 

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading || newValue === '') return;

 

    var selectedDate = new Date(newValue);

    var day = selectedDate.getDay(); // 0 = Sunday

 

    if (day !== 0) {

        g_form.showFieldMsg('your_date_field', 'Please select a Sunday.', 'error');

        g_form.setValue('your_date_field', '');

    } else {

        g_form.hideFieldMsg('your_date_field', true

);

    }

}

I tested with these dates - 2025-04-13 (which is a Sunday)

 

System Behavior:

 

No error message

 

Field value is accepted

 

2)2025-04-14 (which is a Monday)

 

System Behavior:

 

Error shown: "Please select a Sunday."

 

Field value is cleared automatically.

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

Oh that's good. But I need every OTHER sunday depending when the pay period starts. 

OTHER - you mean alternative ? @Adam Peterson 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

 

 

And that too depending on pay period @Adam Peterson 

 

I think that would be very dynamic. If there is some fixed pattern we could still cone up with script. 

 

Then maybe it's better off as a select box field where you give options. If you some fixed pattern let me know could try to come up with a script otherwise select box is fine. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY