在 SuiteScript 中,您可以使用 record.submitFields 设置自定义表单字段吗?
In SuiteScript, can you set the customform field using record.submitFields?
我有一个合作伙伴记录,如果类别字段设置为特定值,我想更改表单。但是,我不能将它与某些 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;
}
}
}
我有一个合作伙伴记录,如果类别字段设置为特定值,我想更改表单。但是,我不能将它与某些 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;
}
}
}