- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2024 11:09 PM
If the variable is "Please select the start date from which the change should take effect (only full months from the 1st of a calendar month):" and type is "Date " then default value should be "1st of current month"
How to achieve this using client script
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 10:26 AM
HI @Gangaiah Deepu ,
I trust you are doing great.
Please find below code :
(function onLoad() {
// Ensure this runs only on the form view
if (g_form.isNewRecord()) {
var today = new Date();
var firstDayOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
// Format the date to YYYY-MM-DD for setting the date field value
var formattedDate = firstDayOfMonth.toISOString().split('T')[0];
// Replace 'your_date_field' with the actual field name
g_form.setValue('your_date_field', formattedDate);
}
})();
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 09:51 AM
Hello,
If I am following your request correctly here, the client script may look something like this (be sure to make your changes for your actual field value):
function onLoad() {
// Get current date
var currentDate = new Date();
// Set date to first day of current month
currentDate.setDate(1);
// Format date to yyyy-mm-dd
var year = currentDate.getFullYear();
var month = (currentDate.getMonth() + 1 < 10) ? '0' + (currentDate.getMonth() + 1) : currentDate.getMonth() + 1;
var day = (currentDate.getDate() < 10) ? '0' + currentDate.getDate() : currentDate.getDate();
var formattedDate = year + '-' + month + '-' + day;
// Set default value for date field
g_form.setValue('date_field_name', formattedDate);
}
Hope this helps get you going!
Thanks,
-Rob
** Please remember to mark replies Helpful and/ or Correct when appropriate **
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 10:26 AM
HI @Gangaiah Deepu ,
I trust you are doing great.
Please find below code :
(function onLoad() {
// Ensure this runs only on the form view
if (g_form.isNewRecord()) {
var today = new Date();
var firstDayOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
// Format the date to YYYY-MM-DD for setting the date field value
var formattedDate = firstDayOfMonth.toISOString().split('T')[0];
// Replace 'your_date_field' with the actual field name
g_form.setValue('your_date_field', formattedDate);
}
})();
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi