我正在编写一个脚本,以从一个字段中获取值并将其放入NetSuite的列表字段中。我相信问题是因为保存记录后,试图在不包含该值的列表中设置一个值。
我希望在脚本上下文中设置该选项时,它会自动失败,如何防止错误消息出现并允许创建记录但又不填充该字段? < / p>
场景-值放置在此字段中,脚本尝试将该值映射到列表值(它不存在),该记录仍应保存,但未设置该数据-没有错误。
/**
* @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
};
});
答案 0 :(得分:0)
我认为解决方案不应阻止显示消息,而应防止在无效值时设置该值。您可以首先尝试获取该列表中所有有效选项的数组,其次检查要使用的值是否包含在数组中,如果是,则设置该值。
具体来说:
www.mozilla.org
有关功能getSelectOptions的更多详细信息,请参阅Netsuite帮助中心(搜索Field.getSelectOptions)
答案 1 :(得分:0)
只需用try catch包装任何和所有netsuite逻辑即可。 Netsuite中的LOC超过614,00,并且可以正常工作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;
}