0

ServiceNow を使用しています。フォーム onSubmit を検証する必要があります。データを検証するスクリプト インクルードで GlideAjax を使用しています。Ajax 関数calendarDate(response)からクライアント スクリプト内の他の関数に変数を渡すにはどうすればよいですか? グライド ajax 関数がエラー メッセージを返した場合、変数 "isValid" を false に設定したいと考えています。

これは、GlideAjax を使用しないクライアント スクリプトを使用して簡単に実行できました。var isValid = checkLnrDates(); のように、変数 isValid を関数の結果に設定するだけです。

ただし、GlideAjax を使用しているときに関数呼び出しに等しい変数を設定しても、使用できる値は返されません。GlideAjax 関数が呼び出されて処理される方法を理解していない可能性があります。

カタログ クライアント スクリプト onSubmit

function onSubmit () {
  var isValid = checkLnrDates();
  if (isValid == false) {
  g_form.submitted = false;
  return false;
  }
}


function checkLnrDates() {
  var start = g_form.getValue('start_date');
  //Check calendar date format valid YYYY-MM-DD
  //Script include ClientDateTimeUtils checks the input data
  var ajaxCalendarDate = new GlideAjax('ClientDateTimeUtils');
  ajaxCalendarDate.addParam('sysparm_name', 'validateCalendarDate');
  ajaxCalendarDate.addParam('sysparm_userDate', start);
  ajaxCalendarDate.getXML(calendarDate);
}


function calendarDate(response){
  //This is where we get the response returned from the ClientDateTimeUtils script include ajax function
  var answer = response.responseXML.documentElement.getAttribute("answer"); 
  if (answer != 'true'){
  g_form.showFieldMsg('start_date', answer,'error');
  //How can I pass the value of a variable to the function above? I want to set isValid to false
isValid = false; 
return false;
  }
  }
4

2 に答える 2

1

これを試して:

    function onSubmit(){
      checkLnrDates();
      return false;
    }


    function checkLnrDates() {
      var start = g_form.getValue('start_date');
      //Check calendar date format valid YYYY-MM-DD
      //Script include ClientDateTimeUtils checks the input data
      var ajaxCalendarDate = new GlideAjax('ClientDateTimeUtils');
      ajaxCalendarDate.addParam('sysparm_name', 'validateCalendarDate');
      ajaxCalendarDate.addParam('sysparm_userDate', start);
      ajaxCalendarDate.getXML(calendarDate);
    }


    function calendarDate(response){
      //This is where we get the response returned from the ClientDateTimeUtils script include ajax function
      var answer = response.responseXML.documentElement.getAttribute("answer"); 
      if (answer != 'true'){
          g_form.showFieldMsg('start_date', answer,'error');
         return false;
      }
      else
        g_form.submit();
 }
于 2015-06-03T20:19:12.303 に答える