【问题标题】:In SuiteScript, can you set the customform field using record.submitFields?在 SuiteScript 中,您可以使用 record.submitFields 设置自定义表单字段吗?
【发布时间】:2020-09-18 18:44:05
【问题描述】:

我有一个合作伙伴记录,如果类别字段设置为某个值,我想在其中更改表单。但是,我不能将它与某些 SuiteScript 函数一起使用,因为更改表单会清除对记录所做的任何更改。我正在尝试使用 afterSubmit 函数来解决此问题,该函数将使用 record.SubmitFields 更改表单,然后 redirect.toRecord 重新加载更改后的页面。但是,它不会更改表单值。有没有办法用 record.submitFields 做到这一点?我做错了什么吗?

            var currentRecord = scriptContext.newRecord;
            var category = currentRecord.getValue('category');

            if(category == '3'){
                try{
                    record.submitFields({
                        type: record.Type.PARTNER,
                        id: currentRecord.id,
                        values: {
                            'customform': '105'
                        }
                    });
                    log.debug('success');
                } catch (e) {
                    log.error({title: 'error', details: e});
                }

            }

            redirect.toRecord({
                type: 'partner',
                id: currentRecord.id,
            });

        }

【问题讨论】:

    标签: netsuite suitescript suitescript2.0


    【解决方案1】:

    是的,你可以。每当您为记录创建 url 时,您通常可以添加一个采用表单 id 的 cf 参数。如果您设置字段“customform”,它与您使用的值相同。因此,只需跳过 submitFields 部分并执行以下操作:

    redirect.toRecord({
        type: 'partner',
        id: currentRecord.id,
        parameters:{
           cf:105
        }
    });
    

    您还可以使用 submitFields 调用设置自定义表单,但这仅适用于某些类型的记录。

    如果您需要在 beforeLoad 中执行此操作,这里是 Typescript 中的一个片段。避免无限循环的诀窍是检查您是否已经拥有正确的形式:

    export function beforeLoad(ctx){
        let rec : record.Record  = ctx.newRecord;
        let user = runtime.getCurrentUser();
        if(user.roleCenter =='EMPLOYEE'){
            if(rec.getValue({fieldId:'assigned'}) != user.id){
                throw new Error('You do not have access to this record');
                return;
            }
        }else{
            log.debug({
                title:'Access for '+ user.entityid, 
                details:user.roleCenter
            });
        }
        
        if(ctx.type == ctx.UserEventType.EDIT){
            var approvalForm = runtime.getCurrentScript().getParameter({name:'custscript_kotn_approval_form'});
            let rec : record.Record  = ctx.newRecord;
            if( 3 == rec.getValue({fieldId:'custevent_kotn_approval_status'})){
                if(approvalForm != rec.getValue({fieldId:'customform'}) && approvalForm != ctx.request.parameters.cf){
                    redirect.toRecord({
                        type: <string>rec.type,
                        id : ''+rec.id,
                        isEditMode:true,
                        parameters :{
                            cf:approvalForm
                        }
    
                    });
                    return;
                }
            }
        } 
    

    【讨论】:

    • 是否可以在加载之前执行此操作?我想找到一种在用户第一次拉出记录时加载正确表单的方法。当我将代码放在那里时,页面无休止地加载然后崩溃。
    • 放在beforeLoad时卡在了死循环中。显然,由于表单值没有保存到数据库中,除非您重新提交记录,否则旧表单将始终拉起。
    • 您是否尝试将其移动到 pageInit 客户端脚本而不是加载前?
    • onBeforeLoad 上下文也可以访问请求参数。我已经更新了示例以显示如何检查。
    • @bknights 这只有在记录处于编辑模式时才有效吗?有没有办法在记录视图中做到这一点?
    猜你喜欢
    • 1970-01-01
    • 2021-10-27
    • 1970-01-01
    • 2020-02-22
    • 1970-01-01
    • 1970-01-01
    • 2021-12-18
    • 1970-01-01
    • 2016-06-19
    相关资源
    最近更新 更多