Как предотвратить отображение ошибки в NetSuite? - PullRequest
0 голосов
/ 24 октября 2018

Я пишу скрипт для получения значения из одного поля и помещения его в поле списка в NetSuite.Я полагаю, что проблема заключается в том, что при сохранении записи значение пытается быть задано в списке, который не содержит это значение.

Я хочу, чтобы это происходило автоматически при установке в контексте моего скриптаКак я могу предотвратить появление сообщения об ошибке и разрешить создание записи, но без заполнения этого поля?

Сценарий - значение помещено в это поле, сценарий пытается отобразить это значениедо значения списка (ЭТОГО НЕ СУЩЕСТВУЕТ), запись все равно должна быть сохранена, но без этих данных - НЕТ ОШИБОК.

/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 * @NModuleScope SameAccount
 */
define(['N/record', 'N/log'],
/**
 * @param {record} record
 */
function(record) {

    function customer_beforeLoad(scriptContext) {

    }

    function customer_beforeSubmit(scriptContext) {

        //Segment
        setNonIntegrationFieldValue(scriptContext, 'custentity_cus_segmentintegration', 'custentity_cus_segment');
        //Currency
        setNonIntegrationFieldValue(scriptContext, 'custentity_cus_primarycurrencyintegratio', 'currency');
        //Billing Cycle
        setNonIntegrationFieldValue(scriptContext, 'custentity_cus_billingcycleintegration', 'custentity_cus_billingcycle');
        //Type
        setNonIntegrationFieldValue(scriptContext, 'custentity_cus_typeintegration', 'custentity_cus_type');
        //Industry
        setNonIntegrationFieldValue(scriptContext, 'custentity_cus_industryintegration', 'custentity_esc_industry');
        //Sales Rep
        setNonIntegrationFieldValue(scriptContext, 'custentity_cus_salesrepintegration', 'salesrep');
    }

    function customer_afterSubmit(scriptContext) {

    }

    function setNonIntegrationFieldValue(scriptContext, integrationFieldName, actualFieldName){
      try {
        var integrationFieldValue = scriptContext.newRecord.getValue(integrationFieldName);
        if(integrationFieldValue == '' || integrationFieldValue == null){
            scriptContext.newRecord.setValue({
                fieldId: actualFieldName,
                value: ''
            });
        } else {
            scriptContext.newRecord.setText({
                fieldId: actualFieldName,
                text: integrationFieldValue
            });
        }
      } catch(e){
        log.error({
          title: "setNonIntegrationFieldValue() has encountered an error.",
          details: e.message
        });
        //nlapiLogExecution('ERROR','setNonIntegrationFieldValue() has encountered an error.', errText(e));
      }
    }

    return {
        //beforeLoad: customer_beforeLoad,
        beforeSubmit: customer_beforeSubmit,
        //afterSubmit: customer_afterSubmit
    };

});

Ответы [ 2 ]

0 голосов
/ 20 ноября 2018

Просто оберните ЛЮБУЮ И ВСЕ логику netsuite с помощью try catch.У нас более 614,00 LOC в netsuite, и это работает на 100%:

try {
   // your code here
} catch (e) {
   // this ternary operator will catch all the ns errors. you can fail silently here
   var error = e.details || e.message || e.toString();
   throw error;
}
0 голосов
/ 16 ноября 2018

Я думаю, что решение не должно препятствовать отображению сообщения, вместо этого оно должно предотвращать установку значения, когда оно недопустимо.Во-первых, вы можете попытаться получить массив всех допустимых опций в этом списке, во-вторых, проверить, содержится ли значение, которое вы хотите использовать, в массиве, если да, то установите значение.

Чтобы быть точным:

var actualField = scriptContext.form.getField(actualFieldName);
var options = actualField.getSelectOptions();
var integrationFieldValue = scriptContext.newRecord.getValue(integrationFieldName);
if (options.indexOf(integrationFieldValue) > -1) {
scriptContext.newRecord.setText({
                fieldId: actualFieldName,
                text: integrationFieldValue
            });
}

Для получения дополнительной информации о функции getSelectOptions, пожалуйста, обратитесь к Справочному центру Netsuite (поиск Field.getSelectOptions)

...