The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Need Help W/ Planned Start/End Date Client Script - Time Date

JamesEcoStratus
Mega Guru

Hi Community,

I have the following requirement:

  • ✓Normal Change Planned Start / End Date
  • ✓As a change manager, I want to enter planned Start / End Date which must be in the future.
  • ✓Start / End Date must be recorded in the future for Normal changes.
  • ✓Start Date Must be Today or in the future
  • ✓End Date Must be in the Future
  • ✓IF the user selects a date in the past, a message will pop-up.
    • ✓"You must select a date in the future"
  • ✓Validate planned start / end date are in the future for Normal changes.

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

1 ACCEPTED SOLUTION

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);


  }


}


View solution in original post

8 REPLIES 8

Cheyenne1
Kilo Guru

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);


  }


}


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);


  }


}


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


Cheyenne1
Kilo Guru

Hey James, Can you post a screen shot of your client script form?