Validate In-Line Edits in Netsuite

吃可爱长大的小学妹 提交于 2019-12-07 16:21:37

问题


I need to validate inline editing in NetSuite.

I already have a Client Script in place that works great when editing the record normally.

I tried adding a User Event script that on the before save function that validates the record, but it appears this is ignored with inline editing.

Has anybody ran into this before?

Any insight you can provide would be helpful. Thanks!

Edits:

The relevant code from the UE script:

function beforeSubmit(type){
    if (type == "create" || type == "edit" || type == "xedit") {
        var status = nlapiGetContext().getSetting("SCRIPT", "...");
        var amount = Number(nlapiGetContext().getSetting("SCRIPT", "..."));

        var nr = nlapiGetNewRecord();
        var entitystatus = nr.getFieldValue("entitystatus");
        var projectedtotal = Number(nr.getFieldValue("projectedtotal"));
        if (entitystatus == status && projectedtotal >= amount) {
            var statusText = nr.getFieldText("entitystatus");
            var message = "ERROR...";
            throw nlapiCreateError("...", message, true);
        }
    }
}

This applies to the opportunity record.

The field being validated is Projected Total with id projectedtotal.


回答1:


My mistake, I misunderstood how xedit handled nlapiGetNewRecord(). Calling nlapiGetNewRecord when in xedit only returns the edited fields, not the entire record. Thus, the if statement was never true in xedit mode, because either the amount or the status would be null (it was very unlikely the user would edit both at the same time, and validation relies on both these fields' values).

I edited the code to lookup the field value if it is not present in the new record. Now everything works as expected!

Thanks everyone for the help!

For reference, the corrected code is below.

function beforeSubmit(type){
    if (type == "create" || type == "edit" || type == "xedit") {
        var status = nlapiGetContext().getSetting("SCRIPT", "...");
        var amount = Number(nlapiGetContext().getSetting("SCRIPT", "..."));

        var nr = nlapiGetNewRecord();
        //Attempt to get values normally
        var entitystatus = nr.getFieldValue("entitystatus");
        var projectedtotal = Number(nr.getFieldValue("projectedtotal"));

        var id = nr.getId();

        //If values were null, it's likely they were not edited and
        //thus not present in nr. Look them up.
        if(!entitystatus){
            entitystatus = nlapiLookupField("opportunity", id, "entitystatus");
        }
        if(!projectedtotal){
            projectedtotal = Number(nlapiLookupField("opportunity", id, "projectedtotal"));
        }

        if (entitystatus == status && projectedtotal >= amount) {
            var message = "ERROR...";
            throw nlapiCreateError("101", message, true);
        }
    }
}



回答2:


In your user event are you checking the value of the type parameter. For inline editing, the value of the type is 'xedit'.



来源:https://stackoverflow.com/questions/33977092/validate-in-line-edits-in-netsuite

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!