Netsuite 在SuiteScript中,能否使用record.submitFields设置customform字段?

Netsuite 在SuiteScript中,能否使用record.submitFields设置customform字段?,netsuite,suitescript,suitescript2.0,Netsuite,Suitescript,Suitescript2.0,我有一个合作伙伴记录,如果类别字段设置为某个值,我想在其中更改表单。但是,我不能将其用于某些SuiteScript函数,因为更改表单会清除对记录所做的任何更改。我正在尝试使用afterSubmit函数来解决这个问题,该函数将使用record.SubmitFields来更改表单,然后使用redirect.toRecord来重新加载带有更改的页面。但是,它不会更改表单值。是否有一种方法可以使用record.submitFields执行此操作?我做错什么了吗 var curre

我有一个合作伙伴记录,如果类别字段设置为某个值,我想在其中更改表单。但是,我不能将其用于某些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,
            });

        }

是的,你可以。每当为记录创建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;
            }
        }
    } 
加载前导出功能(ctx){
让rec:record.record=ctx.newRecord;
让user=runtime.getCurrentUser();
如果(user.roleCenter=='EMPLOYEE'){
if(rec.getValue({fieldId:'assigned'})!=user.id){
抛出新错误(“您无权访问此记录”);
返回;
}
}否则{
log.debug({
标题:'Access for'+user.entityid,
详细信息:user.roleCenter
});
}
if(ctx.type==ctx.UserEventType.EDIT){
var approvalForm=runtime.getCurrentScript().getParameter({name:'custscript\u kotn\u approval\u form'});
让rec:record.record=ctx.newRecord;
if(3==rec.getValue({fieldId:'custevent\u kotn\u approval\u status'})){
if(approvalForm!=rec.getValue({fieldId:'customform'})和&approvalForm!=ctx.request.parameters.cf){
重新定向记录({
类型:rec.type,
id:''+rec.id,
isEditMode:对,
参数:{
cf:批准表格
}
});
返回;
}
}
} 

是否可以在加载前执行此操作?我想找到一种方法,在用户第一次提取记录时加载正确的表单。当我将代码放在那里时,页面无休止地加载,然后崩溃。在加载前将其放入无限循环中。显然,由于表单值没有保存到数据库中,旧表单除非您重新提交该记录,否则我将一直调出。您是否尝试将其移动到pageInit客户端脚本而不是加载前脚本?onBeforeLoad上下文还可以访问请求参数。我已更新了示例,以说明如何检查该参数。@bk这仅在记录处于编辑模式时有效?是否有办法在r上执行此操作ecord视图?