- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 05:56 AM
Hi All,
I am trying to populate a Date/Time field based on a condition ( using onChange Client Script ) but is not working as expected.
var d = new Date();
if (newValue == 'true') {
g_form.setValue('accept_time_mdm', d);
}
Can someone please help me how to get the field populated with the format which I have shared?
Regards,
Saurabh Chatterjee
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 05:58 AM
HI @chatsaurav19 ,
I trust you are doing great.
Here's an updated version of your script:
var d = new Date();
// Check your condition
if (newValue == 'true') {
// Format the date into YYYY-MM-DD HH:MM:SS
var formattedDate = d.getFullYear() + '-' +
('0' + (d.getMonth() + 1)).slice(-2) + '-' + // Months are zero-based
('0' + d.getDate()).slice(-2) + ' ' +
('0' + d.getHours()).slice(-2) + ':' +
('0' + d.getMinutes()).slice(-2) + ':' +
('0' + d.getSeconds()).slice(-2);
// Set the formatted date to the field
g_form.setValue('accept_time_mdm', 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
12-06-2023 05:58 AM
HI @chatsaurav19 ,
I trust you are doing great.
Here's an updated version of your script:
var d = new Date();
// Check your condition
if (newValue == 'true') {
// Format the date into YYYY-MM-DD HH:MM:SS
var formattedDate = d.getFullYear() + '-' +
('0' + (d.getMonth() + 1)).slice(-2) + '-' + // Months are zero-based
('0' + d.getDate()).slice(-2) + ' ' +
('0' + d.getHours()).slice(-2) + ':' +
('0' + d.getMinutes()).slice(-2) + ':' +
('0' + d.getSeconds()).slice(-2);
// Set the formatted date to the field
g_form.setValue('accept_time_mdm', 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
12-06-2023 08:09 AM
Hi @Amit Gujarathi Thank you! It worked.... Can you please let me know how to achieve the same by checking the 'time zone' of the user and then populating the field based on the user's time zone?
Regards,
Saurabh