beforeLoad是Suitescript Netsuite中的一个功能。

huangapple go评论56阅读模式
英文:

beforeLoad suitescript netsuite

问题

我创建了一个脚本,用于在状态为“Pending Fulfillment”或“Pending Approval”时执行。

function beforeLoad(context) {
    var currRec = context.newRecord;
    var status = currRec.getValue('status');
    var mem = currRec.getValue('memo');
    var idSo = currRec.getValue('id');
    
    if (status === 'Pending Fulfillment') {
        record.submitFields({
            type: record.Type.SALES_ORDER,
            id: idSo,
            values: {
                trandate: null
            },
        });
    } else if(status === 'Pending Approval'){
        record.submitFields({
            type: record.Type.SALES_ORDER,
            id: idSo,
            values: {
                trandate: null
            },
        });
    }
}

但是当查看一个销售订单时,trandate字段不会立即响应。只有在刷新一次后,脚本才会生效。

英文:

i create an script beforeLoad if status Pending Fulfillment or approval

function beforeLoad(context) {
    

    var currRec = context.newRecord;
        var status = currRec.getValue('status')
        var mem = currRec.getValue('memo')
        var idSo = currRec.getValue('id')
        // log.debug('status', status)
        if (status === 'Pending Fulfillment') {
            record.submitFields({
                type: record.Type.SALES_ORDER,
                id: idSo,
                values: {
                    trandate: null
                },
                
            });
        } else if(status === 'Pending Approval'){
            record.submitFields({
                type: record.Type.SALES_ORDER,
                id: idSo,
                values: {
                    trandate: null
                },
                
            });
        }
    
    }

but when view an sales order that trandate not response. only when once refresh, the script worked

答案1

得分: 0

如果我理解正确,你希望在记录加载时将 trandate 设为 null。这里的情况是,在触发 beforeLoad 之前,它会运行其下方的代码,然后在浏览器中加载记录。你提交的数据在下一次刷新之前不会反映在记录中,因为请求的数据是之前的(在新值提交之前)。

你也不能在 beforeLoad 入口点上使用 setValues。然而,它只会应用于新创建的记录(在编辑时的 beforeLoad)。

清除记录创建后的 trandate 的原因是什么?如果这是业务标准要求,为什么不在创建记录后运行该代码,并在 afterSubmit 中清除 trandate。虽然我不知道是否会因为它是一个必填字段而抛出错误。

英文:

If I understood correctly, you want trandate to be null on record load. What's happening here is once beforeLoad triggers, it runs the code underneath it and then loads the record on the browser. The data you submitted will not reflect on the record until the next refresh since the requested data was the previous (before new value submission).

You also cannot setValues on beforeLoad entry point. However, it will only apply on new records created (beforeLoad on Edit).

What is the reason for clearing the trandate after the record is created? If it's to be a business standard requirement, why not run that code after you create the record and clear the trandate on afterSubmit. Though I don't know if you will get thrown an error since it is a mandatory field.

huangapple
  • 本文由 发表于 2023年5月26日 16:01:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76338812.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定