getDateFromFormat not defined inside client script

agarc657
Giga Contributor

Hello,

I have a question regarding the getDateFromFormat function. I need to ensure that the date entered is at least 7 days out from the current date this is what i have right now

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

                  if (newValue === '') {

                                  g_form.hideFieldMsg('date', true);

                                return;

                                  }

      //Check if date is less than 7 days away from now

          var disc = getDateFromFormat(newValue, g_user_date_format);

          var now = new Date();

          var durationInSec = (disc - now)/1000;

          if(durationInSec < (7*24*3600)){

                          g_form.setValue('date', '');

                          g_form.showFieldMsg('date', "A minimum of 7 days notice is required to process this request", 'error');

  }

}

however I get the following error in my log "Error while running Client Script "Validate need by date is at least 7 days": ReferenceError: getDateFromFormat is not defined"

Is getDateFromFormat   not already defined for me? im using Istanbul .

any help would be amazing, sorry if im missing something super easy.

1 ACCEPTED SOLUTION
4 REPLIES 4

How would this solve the error im getting ? im pretty new to servicenow sorry


israel62
Kilo Contributor

Are you sure that the function getDateFromFormat() does exists? Try looking at the Wiki and see if there is a function that can help you:


http://wiki.servicenow.com/index.php?title=GlideSystem_Date_and_Time_Functions#gsc.tab=0