getMonth, getDate, getFullYear return NaN
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2022 04:46 AM
Hi Everyone,
Need your help with my requirement. To give context, my requirement is everytime a user populate the "New Expiry Date" date/time field, the system will automatically add 1 day and the hours should be 12mn (Ex: user input 09/14/2022 15:23:00, system will change the date and save it as 09/15/2022 00:00:00.
I have created a script and I used alert to show the output. In the alert message the output showing is correct but when I tried to push that output to a specific date field it show NaN for Year, Date, and Month. Please see screenshot below:
But in the field display it shows like this:
Below is my client script onChange:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var date_obj = g_form.getValue("new_expiry_date");
var dmonth = new Date(date_obj).getMonth() + 1;
var dday = new Date(date_obj).getDate() + 1;
var dyear = new Date(date_obj).getFullYear();
var dhour = new Date(date_obj).getHours();
var dminute = new Date(date_obj).getMinutes();
var dsecond = new Date(date_obj).getSeconds();
var pmonth = parseInt(dmonth);
var pday = parseInt(dday);
var pyear = parseInt(dyear);
//var smonth = new Date(date_obj).setDate(dmonth);
// var setmonth = new Date(dmonth).setMonth();
var tot = (pmonth+'/'+pday+'/'+pyear+" "+"00"+":"+"00"+":"+"00");
//var future_date = new Date(new Date().getTime() + minutes_from_now*60000);
//var future_date = g_form.getValue("stored_date");
//var futuredate = new Date(future_date).getTime();
//var format = g_user_date_time_format;
// var result = compareDates(date_obj, future_date);
//if (futuredate > dateobj) {
//alert('New Expiry Date should not be earlier than the date of the Project to be extended(Project Expiry Date)');
//g_form.clearValue("new_expiry_date");
g_form.setValue("new_expiry_date",tot);
//return;
//alert(tot);
}
Hope you can help me as I am not that good with scripting
Thanks in Advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2022 04:55 AM
hello
do glidedatetime before setting like below
var gdt = new GlideDateTime(tot);
g_form.setValue("new_expiry_date",gdt);
Hope this helps
Mark the answer correct if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2022 04:41 PM
As per documentation GlideDateTime doesn't work on client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2022 04:58 AM
Hello,
Please check once with below code the below code will add 30 days to new_expiry_date value and populate in alert. you can change as per your need.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var date_obj = g_form.getValue("new_expiry_date");
var plannedDate = new Date(getDateFromFormat(date_obj, g_user_date_time_format));
plannedDate.setDate(plannedDate.getDate() + 30);
var plannedDateStr = formatDate(plannedDate, g_user_date_time_format);
alert(plannedDateStr);
g_form.setValue("new_expiry_date", plannedDateStr);
}
Else check with below:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var date_obj = g_form.getValue("new_expiry_date");
var plannedDate = new Date(getDateFromFormat(endDate, g_user_date_time_format));
var dmonth = plannedDate.getMonth() + 1;
var dday = plannedDate.getDate() + 1;
var dyear = plannedDate.getFullYear();
var dhour = plannedDate.getHours();
var dminute = plannedDate.getMinutes();
var dsecond = plannedDate.getSeconds();
var pmonth = parseInt(dmonth);
var pday = parseInt(dday);
var pyear = parseInt(dyear);
var tot = (pmonth+'/'+pday+'/'+pyear+" "+"00"+":"+"00"+":"+"00");
g_form.setValue("new_expiry_date",tot);
}
Please mark my respsone as helpful/correct, if it answer your question.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2022 11:06 PM
hello
Just wanted to check with you, if the above response answered your question. If yes, then please do close this thread/question by marking the appropriate response as correct.
If you still need any further help or guidance on this then please update those on this question.
Thanks