- 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:05 AM
Hi @Simona6 ,
We should use the GLIDEDATETIME API for this,
Here is the script,
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var start = g_form.getValue('start_date');
var end = new GlideDateTime();
end.setDisplayValue(start);
end.addDaysLocalTime(2);
g_form.setValue('end_date', end);
}
If this helps you kindly mark it as correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2023 12:28 AM
Glidedatetime API can't be used in client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2023 12:24 AM
are both the fields of type date?
can you share screenshot?
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:32 AM
@Ankur Bawiskar these are two field with type-date