验证Netsuite中的内联编辑 [英] Validate In-Line Edits in Netsuite

查看:104
本文介绍了验证Netsuite中的内联编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要验证NetSuite中的内联编辑.

我已经有一个客户端脚本,该客户端脚本在正常编辑记录时效果很好.

我尝试在验证记录的before save函数上添加一个User Event脚本,但是看起来它被内联编辑忽略了.

以前有人遇到过吗?

您可以提供的任何见解都会有所帮助.谢谢!

UE脚本中的相关代码:

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);
        }
    }
}

这适用于机会记录.

正在验证的字段是ID为projectedtotal的计划总计".

解决方案

我的错误,我误解了xedit如何处理nlapiGetNewRecord().在xedit中调用nlapiGetNewRecord仅返回已编辑的字段,而不返回整个记录.因此,在xedit模式下,if语句永远不会为真,因为数量或状态都将为null(用户不太可能同时编辑两个对象,并且验证依赖于这两个字段的值).

我编辑了代码以查找新记录中不存在的字段值.现在一切都按预期工作!

感谢大家的帮助!

作为参考,更正后的代码如下.

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);
        }
    }
}

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.

解决方案

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);
        }
    }
}

这篇关于验证Netsuite中的内联编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆