如何在SuiteScript中访问NetSuite界面非标准子列表类信息(含Estimate案例)
SuiteScript访问Estimate页面Relationship标签下联系人列表的方法
Estimate页面Relationship标签展示的联系人列表,并非Estimate自身的标准子列表,实际是关联客户(Customer)的联系人记录。以下是两种SuiteScript 2.x的实现方式:
方法一:加载关联客户记录读取联系人子列表
通过Estimate获取关联客户ID,再加载客户记录读取其contact子列表数据:
/** * @NApiVersion 2.x * @NScriptType UserEventScript */ define(['N/record'], function(record) { function afterSubmit(context) { var estimateRec = context.newRecord; // 获取Estimate关联的客户ID var customerId = estimateRec.getValue({fieldId: 'entity'}); if (!customerId) return; // 加载客户记录 var customerRec = record.load({ type: record.Type.CUSTOMER, id: customerId, isDynamic: false }); // 遍历联系人子列表 var contactLineCount = customerRec.getLineCount({sublistId: 'contact'}); for (var i = 0; i < contactLineCount; i++) { var contactId = customerRec.getSublistValue({ sublistId: 'contact', fieldId: 'contact', line: i }); var contactName = customerRec.getSublistValue({ sublistId: 'contact', fieldId: 'contactname', line: i }); // 按需处理联系人数据 log.debug('联系人详情', `ID: ${contactId}, 名称: ${contactName}`); } } return {afterSubmit: afterSubmit}; });
方法二:用搜索直接查找关联联系人
通过搜索筛选与目标客户关联的联系人记录,适合不需要加载完整客户记录的场景:
/** * @NApiVersion 2.x * @NScriptType UserEventScript */ define(['N/search'], function(search) { function afterSubmit(context) { var estimateRec = context.newRecord; var customerId = estimateRec.getValue({fieldId: 'entity'}); if (!customerId) return; // 创建联系人搜索 var contactSearch = search.create({ type: search.Type.CONTACT, filters: [['company', 'anyof', customerId]], columns: ['internalid', 'entityid', 'email'] }); // 遍历搜索结果 contactSearch.run().each(function(result) { var contactId = result.getValue('internalid'); var contactName = result.getValue('entityid'); var contactEmail = result.getValue('email'); log.debug('联系人详情', `ID: ${contactId}, 名称: ${contactName}, 邮箱: ${contactEmail}`); return true; }); } return {afterSubmit: afterSubmit}; });
通用思路提示
遇到Web界面显示但Records Browser未列出的子列表,核心是定位数据的实际归属:
- 用浏览器开发者工具查看页面元素的字段属性,确认关联的实体类型;
- 梳理记录间的关联关系(如Estimate→Customer→Contact),从上游关联实体入手获取数据。
内容的提问来源于stack exchange,提问作者d.k
相关产品推荐
相关产品推荐

