How do I set the default time value when I click the New button?

shiz
Tera Contributor

I created a screen

shiz_1-1731384177305.png

 

When I click on ‘New’ button than 'Week Start On' be set to the current Manday date.

shiz_0-1731384056463.png

How should this be implemented specifically?

 

1 ACCEPTED SOLUTION

Pradeep Thipani
Mega Sage

Hi Shiz,

 

You can achieve that by writing an OnLoad client script for the respective table you are referring.

 

Here is a sample code you can refer:

function onLoad() {
    if (g_form.isNewRecord()) {
        var today = new Date();
        var day = today.getDay();
        // Calculate the Monday of the current week
        var monday = new Date(today.setDate(today.getDate() - (day === 0 ? 6 : day - 1)));
        g_form.setValue('week_start_on', monday.toISOString().split('T')[0]);
    }
}

 

Thanks,

Pradeep

View solution in original post

1 REPLY 1

Pradeep Thipani
Mega Sage

Hi Shiz,

 

You can achieve that by writing an OnLoad client script for the respective table you are referring.

 

Here is a sample code you can refer:

function onLoad() {
    if (g_form.isNewRecord()) {
        var today = new Date();
        var day = today.getDay();
        // Calculate the Monday of the current week
        var monday = new Date(today.setDate(today.getDate() - (day === 0 ? 6 : day - 1)));
        g_form.setValue('week_start_on', monday.toISOString().split('T')[0]);
    }
}

 

Thanks,

Pradeep