这是我创建的用于警告用户的代码,但70%的销售订单是由Web服务(SPS商务,Celigo)创建的。如果系统中已存在采购订单,如何终止网络服务流程(我不想让网络服务保存销售订单)。
- >此代码显示所有销售订单的消息。它没有检查重复的号码。 代码:
function checkForDuplicates() {
//Get the current form customer PO number to validate
var customerpo = nlapiGetFieldValue('otherrefnum');
var filters = new Array();
//Create the search filter for that PO number
filters[0] = new nlobjSearchFilter('otherrefnum', null, 'is', customerpo);
var results = nlapiSearchRecord('salesorder', null, filters, null);
if (results !== null) {
//Is the result this record?
if (results[0].getId() !== nlapiGetRecordId()) {
//No, there is another record, ask user to confirm/cancel saving action
var doWeSave = confirm('Sales Order with the PO number ' + customerpo + ' already exists.\n' +
'Click OK to save a duplicate Sales Order.\n' +
'Click Cancel to return to editing Sales Order.');
if (doWeSave) {
//User selected to save the record
return true;
}
//User selected to cancel the save
return false;
}
}
//No duplicates
return true;
}
您好我使用下面的代码,但它仍显示所有销售订单的消息。
function checkForDuplicates() {
//Get the current form customer PO number to validate
var customerpo = nlapiGetFieldValue('otherrefnum');
//Create the search filter for that PO number
var filters = [
new nlobjSearchFilter('otherrefnum', null, 'is', customerpo),
new nlobjSearchFilter('mainline', null, 'is', 'T'), // filter to mainline makes results faster in many cases
new nlobjSearchFilter('entity', null, 'is', nlapiGetFieldValue('entity'))];
var results = nlapiSearchRecord('salesorder', null, filters, null);
if (results !== null) {
//Is the result this record?
if (results[0].getId() !== nlapiGetRecordId()) {
//No, there is another record, ask user to confirm/cancel saving action
var doWeSave = confirm('Sales Order with the PO number ' + customerpo + ' already exists.\n' +
'Click OK to save a duplicate Sales Order.\n' +
'Click Cancel to return to editing Sales Order.');
if (doWeSave) {
//User selected to save the record
return true;
}
//User selected to cancel the save
return false;
}
}
//No duplicates
return true;
}
答案 0 :(得分:1)
您可以编辑此测试,使其在提交用户事件之前运行。如果是重复,您将抛出错误。您可以保留现有的客户端代码。
注意:您没有对客户进行测试。在繁忙的公司中,客户PO#的重复是相当普遍的,因此您可能应该包含更多过滤器。 e.g:
var filters = [
new nlobjSearchFilter('otherrefnum', null, 'equalto', customerpo),
new nlobjSearchFilter('mainline', null, 'is', 'T'), // filter to mainline makes results faster in many cases
new nlobjSearchFilter('entity', null, 'is', nlapiGetFieldValue('entity'))
];
确保将您的Web服务首选项设置为运行用户事件
设置 - >整合 - > Web服务首选项 确保"禁用Server SuiteScript ..."未经检查
提交前用户事件脚本如下所示:
function beforeSubmitDupeCheck(type) {
if(type == 'create' || type == 'copy' || type == 'edit'){
var customerpo = nlapiGetFieldValue('otherrefnum');
if(!customerpo) return; // just end
if(type == 'edit'){
var oldRec = nlapiGetOldRecord();
if(customerpo == oldRec.getFieldValue('otherrefnum')) return; // didn't change so no re-test
}
var filters = [
new nlobjSearchFilter('otherrefnum', null, 'equalto', customerpo),
new nlobjSearchFilter('mainline', null, 'is', 'T'), // filter to mainline makes results faster in many cases
new nlobjSearchFilter('entity', null, 'is', nlapiGetFieldValue('entity'))
];
if (nlapiGetRecordId()) {
filters.push(new nlobjSearchFilter('internalid', null, 'noneof', [nlapiGetRecordId()]));
}
var duplicates = nlapiSearchRecord('salesorder', null, filters, new nlobjSearchColumn('tranid'));
if (duplicates) throw nlapiCreateError('DUPE_PO', 'Duplicate PO number '+ customerpo +' found on Sales Order '+ duplicates[0].getValue('tranid'));
}
}
下面的示例可以用作应该工作的saveRecord客户端脚本。
function checkForDuplicates() {
//Get the current form customer PO number to validate
var customerpo = nlapiGetFieldValue('otherrefnum');
//Create the search filter for that PO number
var filters = [
new nlobjSearchFilter('otherrefnum', null, 'equalto', customerpo),
new nlobjSearchFilter('mainline', null, 'is', 'T'), // filter to mainline makes results faster in many cases
new nlobjSearchFilter('entity', null, 'is', nlapiGetFieldValue('entity'))
];
if(nlapiGetRecordId()){
filters.push(new nlobjSearchFilter('internalid', null, 'noneof', [nlapiGetRecordId()]));
}
var duplicates = nlapiSearchRecord('salesorder', null, filters, new nlobjSearchColumn('tranid'));
if(!duplicates) return true;
//No, there is another record, ask user to confirm/cancel saving action
return confirm('Sales Order '+ duplicates[0].getValue('tranid') +' with the PO number ' + customerpo + ' already exists.\n' + 'Click OK to save a duplicate Sales Order.\n' + 'Click Cancel to return to editing Sales Order.');
}