- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2022 05:48 AM
We have a true/false flag called Apply Change Freeze'.
If answer for 'Apply Change Freeze' is 'True' >
Display 2 fields > "Select Dates" - a Date field & "Selected Dates" - a Single Line text
OOB there is no utility for DATE field to store multiple values. So I am writing an OnChange client script on date field that whenever it changes, you can pick the values and append it to the list of dates in the string field
I know this is an incorrect script and that only new values are getting stored in Selected Dates Text field. Can someone assist ?
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var appName = g_form.getValue('name');
var select_date = g_form.getValue('u_select_date');
g_form.setValue('u_selected_dates', oldValue + ','+newValue);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2022 05:58 AM - edited ‎11-04-2022 05:59 AM
Hi @Shraddha17
Please try below code:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//var appName = g_form.getValue('name');
var select_date = g_form.getDisplayValue('u_select_date');
var selected_date = g_form.getValue('u_selected_dates');
g_form.setValue('u_selected_dates', selected_date.toString() + ','+ select_date.toString());
}
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2022 05:58 AM - edited ‎11-04-2022 05:59 AM
Hi @Shraddha17
Please try below code:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//var appName = g_form.getValue('name');
var select_date = g_form.getDisplayValue('u_select_date');
var selected_date = g_form.getValue('u_selected_dates');
g_form.setValue('u_selected_dates', selected_date.toString() + ','+ select_date.toString());
}
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2022 06:08 AM
Thanks Anubhav, it works!
However, now it shows below string in Selected Dates
, 2022-11-11 , 2022-11-17 , 2022-12-01
How do we remove 1st comma ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2022 06:15 AM
Got this working..
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var select_date = g_form.getValue('u_select_date');
var selected_date = g_form.getValue('u_selected_dates');
if(selected_date == ''){
g_form.setValue('u_selected_dates', selected_date + select_date);
} else {
g_form.setValue('u_selected_dates', selected_date + ' , ' + select_date);
}
}