You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用User Event Script 2.1创建Entity Group记录?

NetSuite脚本创建Entity Group记录的解决方案

核心问题修正

NetSuite SuiteScript中创建Entity Group时,不能直接用字符串'entitygroup'指定记录类型,需使用官方提供的枚举值或确认正确的内部ID:

  • 对于SuiteScript 2.x:使用record.Type.ENTITY_GROUP(需引入N/record模块)
  • 对于SuiteScript 1.0:直接使用'entitygroup'作为nlapiCreateRecord的参数

字段取值修正

注意字段的有效值格式:

  • grouptype需传入大写的内部ID,比如员工组对应'EMPLOYEE'(而非'Employee')
  • dynamic字段在1.0中需传入字符串'T'/'F',2.x中传入布尔值即可

修改后的代码示例

SuiteScript 2.x版本

define(['N/record', 'N/log'], function(record, log) {
    function entityGroupCreation(name, subAbbrev, searchId){
        const entityGroupRec = record.create({ 
            type: record.Type.ENTITY_GROUP 
        });
        log.debug("entityGroupRec", entityGroupRec);
        entityGroupRec.setValue('grouptype', 'EMPLOYEE');
        entityGroupRec.setValue('dynamic', true);
        entityGroupRec.setValue('groupname', `${subAbbrev} Folder Grp - ${name}`);
        entityGroupRec.setValue('savedsearch', searchId);
        return entityGroupRec.save({ 
            enableSourcing: true, 
            ignoreMandatoryFields: true 
        });
    }

    return { entityGroupCreation };
});

SuiteScript 1.0版本

function entityGroupCreation(name, subAbbrev, searchId){
    const entityGroupRec = nlapiCreateRecord('entitygroup');
    nlapiLogExecution('DEBUG', 'entityGroupRec', entityGroupRec);
    nlapiSetFieldValue('grouptype', 'EMPLOYEE');
    nlapiSetFieldValue('dynamic', 'T');
    nlapiSetFieldValue('groupname', subAbbrev + ' Folder Grp - ' + name);
    nlapiSetFieldValue('savedsearch', searchId);
    return nlapiSubmitRecord(entityGroupRec, true, true);
}

额外注意事项

  • 确保脚本角色拥有Entity Group记录的创建权限
  • 确认savedsearch参数是目标已保存搜索的内部ID数值,且该搜索对当前角色可见
  • 若仍提示类型不存在,可通过NetSuite后台的「记录浏览器」(路径:Customization > Lists, Records, & Fields > Record Types)确认Entity Group的内部ID是否为entitygroup

内容的提问来源于stack exchange,提问作者Maira S

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 16:25:06