how to set due date 2 hours from current date/time using client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 10:27 PM
Hi All,
I have a requirement, based on the type selection I need to auto populate due date 2 hours from current date/time using client script How to do it please any one help me.
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 10:48 PM
Hi @jahnavi chanda , please use this script
// Get the current date/time
var now = new Date();
// Calculate the due date/time by adding 2 hours to the current date/time
var dueDate = new Date(now.getTime() + (2 * 60 * 60 * 1000));
// Set the value of the due date field on the current record
g_form.setValue('due_date', dueDate);
Please mark m answer correct/helpful if it helps to solve your problem.
Regards,
Aditya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 11:43 PM
Hi @aditya174, , Thank you!
By using above script it is updating due date as Wed Apr 12 2023 14:03:53 GMT+0530 (India Standard Time)
But I want this format(12/04/2023 14:03:53) . Do you have any idea. Could you please help with this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 11:51 PM
HI @jahnavi chanda ,
Try this one
var now = new GlideDateTime();
// Calculate the due date/time by adding 2 hours to the current date/time
var dueDate = new GlideDateTime(now.getTime() + (2 * 60 * 60 * 1000));
// Set the value of the due date field on the current record
g_form.setValue('due_date', dueDate);
If my answer has helped with your question, please mark my answer as an accepted solution and give a thumbs up.
Regards,
Aditya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2023 10:10 PM
Hi @jahnavi chanda , please find the updated script in reply to this message of yours, now the date is coming in the format you wanted.
If my answer has helped with your question, please mark my answer as an accepted solution and give a thumbs up.
Regards,
Aditya