簡體   English   中英

檢查銷售訂單是否重復(客戶訂單)保存

[英]Check for Duplicates on sales order(Customer PO) Save

這是我創建的用於警告用戶的代碼,但是70%的銷售訂單是由Web服務(SPS Commerce,Celigo)創建的。 如果采購訂單已存在於系統中,則如何終止Web服務流程(我不想讓Web服務保存銷售訂單)。

->此代碼顯示所有銷售訂單的消息。 它不檢查重復的PO號。 碼:

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;

}

您將編輯此測試,以便它在“先於提交”用戶事件中運行。 如果重復,則會引發錯誤。 您可以保留現有的客戶端代碼。

注意:您不是在對客戶進行測試。 在繁忙的公司中,客戶訂單號重復很常見,因此您可能應該包括更多過濾器。 例如:

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服務首選項,確保未選中“禁用服務器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.');
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM