- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2023 11:23 PM
Two fields on form start date and end date.Expecting as we fill start date(date), end date(date) will be automatically populate date of next two days.
Executing Onchange Client script calling script include but the date format for end date is not same as start date.
e.g if start date is 11/10/2023 then end date is 11-12-2023
Any solution.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2023 01:07 AM
use this onchange client script on start date
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
var dateMS = getDateFromFormat(newValue, g_user_date_format);
dateMS += 2 * 24 * 60 * 60 * 1000; // 2 here indicates days count
var newDT = new Date();
newDT.setTime(dateMS);
g_form.setValue('u_review_end_date',formatDate(newDT, g_user_date_format));
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2023 12:35 AM
you simply want to add 2 days to start date and set in end date right?
if yes then no script include is required for this
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2023 12:43 AM
@Ankur Bawiskar yes as i will change the start date, end date need to be populated with 2days next to start date.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2023 01:06 AM
@Ankur Bawiskar can you please share how to proceed without using script include and without getting any error in date format.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2023 01:07 AM
use this onchange client script on start date
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
var dateMS = getDateFromFormat(newValue, g_user_date_format);
dateMS += 2 * 24 * 60 * 60 * 1000; // 2 here indicates days count
var newDT = new Date();
newDT.setTime(dateMS);
g_form.setValue('u_review_end_date',formatDate(newDT, g_user_date_format));
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2023 01:36 AM
Thank @Ankur Bawiskar
solution works totally fine.
Can we use below approach also instead of using
dateMS += 2 * 24 * 60 * 60 * 1000;
This also works fine from me:
var dateMS = new Date(getDateFromFormat(newValue, g_user_date_format));
dateMS.setDate(dateMS.getDate() + 2);//add 2 days
var newDT = formatDate(dateMS, g_user_date_format);
g_form.setValue('u_review_end_date',newDT);