在 Netsuite 中验证在线编辑

Validate In-Line Edits in Netsuite

我需要在 NetSuite 中验证内联编辑。

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

我尝试添加一个用户事件脚本,该脚本在验证记录的保存功能之前,但看起来这被内联编辑忽略了。

有没有人运行以前参与过这个?

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

编辑:

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 的 Projected Total。

在您的用户事件中,您正在检查类型参数的值。对于内联编辑,type 的值为 'xedit'.

我错了,我误解了xedit是如何处理nlapiGetNewRecord()的。在 xedit 中调用 nlapiGetNewRecord 时仅 returns 编辑的字段,而不是整个记录。因此,if 语句在 xedit 模式下永远不会为真,因为金额或状态将为空(用户不太可能同时编辑两者,并且验证依赖于这两个字段的值)。

我编辑了代码以查找新记录中不存在的字段值。现在一切正常!

感谢大家的帮助!

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

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