The Now Platform® Washington DC release is live. Watch now!
01-13-2017 12:57 PM
Hi Community,
I have the following requirement:
I've created an OnChange script (See Image Attached / Below) to meet the requirements above but having issues getting it to work properly and hoping you could help.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var today = new Date();
var end = new Date(newValue);
var intToday = (today.getUTCFullYear()*10000 ) + (today.getUTCMonth() * 100) + today.getUTCDate();
var intEnd = (end.getUTCFullYear() * 10000) + (end.getUTCMonth() *100) + end.getUTCDate();
//clear the message
g_form.hideFieldMsg(control.name);
//Use UTC conversion, and verify each part is appropriate
if (intEnd >= intToday) {
//this is valid, do nothing
} else {
alert("Date should be today or future date");
g_form.clearValue(control.name);
}
}
Or Should this be changed to be OnSubmit?
Appreciate the help!
Regards,
James
Solved! Go to Solution.
01-13-2017 01:34 PM
Here's what you'll need for Alerts
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var today = new Date();
var end = new Date(newValue);
var intToday = (today.getUTCFullYear() * 10000) + (today.getUTCMonth() * 100) + today.getUTCDate();
var intEnd = (end.getUTCFullYear() * 10000) + (end.getUTCMonth() * 100) + end.getUTCDate();
//clear the message
g_form.hideFieldMsg(control.name);
//Use UTC conversion, and verify each part is appropriate
if (intEnd >= intToday) {
} else {
alert('Date should be today or future date','error');
g_form.clearValue(control.name);
}
}
01-13-2017 01:29 PM
We use a field message instead of alert for this one, this is our code for Preventing past dates.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var today = new Date();
var end = new Date(newValue);
var intToday = (today.getUTCFullYear() * 10000) + (today.getUTCMonth() * 100) + today.getUTCDate();
var intEnd = (end.getUTCFullYear() * 10000) + (end.getUTCMonth() * 100) + end.getUTCDate();
//clear the message
g_form.hideFieldMsg(control.name);
//Use UTC conversion, and verify each part is appropriate
if (intEnd >= intToday) {
} else {
g_form.showFieldMsg(control.name,'Date should be today or future date','error');
g_form.clearValue(control.name);
}
}
01-13-2017 01:34 PM
Here's what you'll need for Alerts
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var today = new Date();
var end = new Date(newValue);
var intToday = (today.getUTCFullYear() * 10000) + (today.getUTCMonth() * 100) + today.getUTCDate();
var intEnd = (end.getUTCFullYear() * 10000) + (end.getUTCMonth() * 100) + end.getUTCDate();
//clear the message
g_form.hideFieldMsg(control.name);
//Use UTC conversion, and verify each part is appropriate
if (intEnd >= intToday) {
} else {
alert('Date should be today or future date','error');
g_form.clearValue(control.name);
}
}
01-13-2017 05:29 PM
Cheyennes Thanks for the help! I testing both scripts and they both failed. I am still able to submit a Normal CHG request in the Past and have it completed in the past.. Any Thoughts?
Very Best
James
01-16-2017 07:49 AM
Hey James, Can you post a screen shot of your client script form?