Prevent Saturday / Sunday from being selected

billi_lumley
ServiceNow Employee
ServiceNow Employee

Attempting to create a catalog client script to prevent a user from selecting Saturday or Sunday using a Date variable.

Tried using the following to prevent a user from selecting Saturday or Sunday and nothing happens when upon submission...

function onSubmit() {

  var udate = getDateFromFormat(g_form.getValue('move_date'), g_user_date_format);

  var userDate = new Date(udate);

  var day = userDate.getDay();

  if (userDay == 0 || userDay == 6) {

  alert('stop');

  return false;

  }

}

1 ACCEPTED SOLUTION

coryseering
ServiceNow Employee
ServiceNow Employee

Hi Billi,



First things first, let's check out what values we're working with. To make it easy, we'll alert the specific values we care about.



Would you mind updating the function like so, and letting us know the output?



function onSubmit() {  


      var udate = getDateFromFormat(g_form.getValue('move_date') , g_user_date_format);


      var userDate = new Date(udate);


      var day = userDate.getDay();  



      alert("Is move_date a valid field? " + g_form.hasField("move_date") + "\n What is its value? " + g_form.getValue("move_date")


                      + "\n Moving date as integer: " + udate + "\n Moving date readable: " + userDate + "\n Moving day: " + day);


                     


      if (userDay == 0 || userDay == 6) {  


              alert('stop');  


      }


     


      return false;


}




This version should alert a box with 4 question/answer pairs. It will also always return false (the form won't submit), but we will move the return false back to the if condition after we determine why it's not working.



Thanks


Cory


View solution in original post

6 REPLIES 6

HomerSimpson.png



I missed that too. Details, details, details. Glad you spotted it!


"userDay" should be "day"

 

Thanks