Ошибка ввода при загрузке сохраненного поиска

#typeerror #suitescript2.0 #saved-searches

Вопрос:

Я продолжаю сталкиваться с этой ошибкой при попытке загрузить сохраненный поиск. «Ошибка типа Не может прочитать свойства неопределенного (чтение «загрузка»)». Я относительно новичок в SuiteScript. Я не вижу, что я делаю неправильно при загрузке сохраненного поиска. Любые предложения будут приветствоваться.

Я пытаюсь выполнить проверку поля с помощью validateField клиентского сценария.

Вот мой код:

 /**  * @NApiVersion 2.0  * @NScriptType ClientScript  */ define(['N/search'], /** * @param {search} search */ function(search) {    /**  * Function to be executed after page is initialized.  *  * @param {Object} scriptContext  * @param {Record} scriptContext.currentRecord - Current form record  * @param {string} scriptContext.mode - The mode in which the record is being accessed (create, copy, or edit)  *  * @since 2015.2  */  function pageInit(scriptContext) {   }   /**  * Function to be executed when field is changed.  *  * @param {Object} scriptContext  * @param {Record} scriptContext.currentRecord - Current form record  * @param {string} scriptContext.sublistId - Sublist name  * @param {string} scriptContext.fieldId - Field name  * @param {number} scriptContext.lineNum - Line number. Will be undefined if not a sublist or matrix field  * @param {number} scriptContext.columnNum - Line number. Will be undefined if not a matrix field  *  * @since 2015.2  */  function fieldChanged(context) {    }  /**  * Function to be executed when field is slaved.  *  * @param {Object} scriptContext  * @param {Record} scriptContext.currentRecord - Current form record  * @param {string} scriptContext.sublistId - Sublist name  * @param {string} scriptContext.fieldId - Field name  *  * @since 2015.2  */  function postSourcing(scriptContext) {   }   /**  * Function to be executed after sublist is inserted, removed, or edited.  *  * @param {Object} scriptContext  * @param {Record} scriptContext.currentRecord - Current form record  * @param {string} scriptContext.sublistId - Sublist name  *  * @since 2015.2  */  function sublistChanged(scriptContext) {   }   /**  * Function to be executed after line is selected.  *  * @param {Object} scriptContext  * @param {Record} scriptContext.currentRecord - Current form record  * @param {string} scriptContext.sublistId - Sublist name  *  * @since 2015.2  */  function lineInit(scriptContext) {   }   /**  * Validation function to be executed when field is changed.  *  * @param {Object} scriptContext  * @param {Record} scriptContext.currentRecord - Current form record  * @param {string} scriptContext.sublistId - Sublist name  * @param {string} scriptContext.fieldId - Field name  * @param {number} scriptContext.lineNum - Line number. Will be undefined if not a sublist or matrix field  * @param {number} scriptContext.columnNum - Line number. Will be undefined if not a matrix field  *  * @returns {boolean} Return true if field is valid  *  * @since 2015.2  */  function validateField(context,search) {  debugger;  var custPmt = context.currentRecord;    if(context.fieldId == 'memo' ) {  var memoValue = custPmt.getValue('memo');    var objSearch = search.load({  id: 'customsearch51957'    });   //add filter  var filter = search.createFilter({  name: 'memo',  operator: search.Operator.IS,  values: memoValue  });   objSearch.filters.push(filter);    var searchResults = objSearch.run().getRange({  start : 0,  end : 10  });  var resultsCount = searchResults.length;   if(resultsCount gt; 0) {  alert(memoValue   " record already exists.");  return false;  }  }  return true;  }   /**  * Validation function to be executed when sublist line is committed.  *  * @param {Object} scriptContext  * @param {Record} scriptContext.currentRecord - Current form record  * @param {string} scriptContext.sublistId - Sublist name  *  * @returns {boolean} Return true if sublist line is valid  *  * @since 2015.2  */  function validateLine(scriptContext) {   }   /**  * Validation function to be executed when sublist line is inserted.  *  * @param {Object} scriptContext  * @param {Record} scriptContext.currentRecord - Current form record  * @param {string} scriptContext.sublistId - Sublist name  *  * @returns {boolean} Return true if sublist line is valid  *  * @since 2015.2  */  function validateInsert(scriptContext) {   }   /**  * Validation function to be executed when record is deleted.  *  * @param {Object} scriptContext  * @param {Record} scriptContext.currentRecord - Current form record  * @param {string} scriptContext.sublistId - Sublist name  *  * @returns {boolean} Return true if sublist line is valid  *  * @since 2015.2  */  function validateDelete(scriptContext) {   }   /**  * Validation function to be executed when record is saved.  *  * @param {Object} scriptContext  * @param {Record} scriptContext.currentRecord - Current form record  * @returns {boolean} Return true if record is valid  *  * @since 2015.2  */  function saveRecord(scriptContext) {   }   return { // pageInit: pageInit, // fieldChanged: fieldChanged, // postSourcing: postSourcing, // sublistChanged: sublistChanged, // lineInit: lineInit,  validateField: validateField // validateLine: validateLine, // validateInsert: validateInsert, // validateDelete: validateDelete, // saveRecord: saveRecord  };   });  

Ответ №1:

Я обнаружил, что мне нужно только передать объект поиска в функцию обратного вызова, а не в validateField функцию.