NetSuite采购申请单:选择申请人后自动填充Location字段需求
在NetSuite采购申请单中自动填充申请人的Location字段
可以通过客户端SuiteScript实现这个需求:监听申请人(requestor)字段的变更事件,加载对应员工记录获取其关联的Location,再自动填充到采购申请单的Location字段。以下是SuiteScript 2.1的代码示例:
/** * @NApiVersion 2.1 * @NScriptType ClientScript * @NModuleScope SameAccount */ define(['N/record', 'N/ui/message'], (record, message) => { // 监听字段变更事件 function fieldChanged(context) { const currentRecord = context.currentRecord; const fieldId = context.fieldId; // 仅处理申请人字段的变更 if (fieldId !== 'requestor') return; const requestorId = currentRecord.getValue({ fieldId: 'requestor' }); if (!requestorId) { // 申请人清空时同步清空Location字段 currentRecord.setValue({ fieldId: 'location', value: '' }); return; } try { // 加载对应员工记录 const employeeRecord = record.load({ type: record.Type.EMPLOYEE, id: requestorId, isDynamic: false }); // 获取员工关联的Location ID const employeeLocationId = employeeRecord.getValue({ fieldId: 'location' }); // 填充采购申请单的Location字段 if (employeeLocationId) { currentRecord.setValue({ fieldId: 'location', value: employeeLocationId }); } else { currentRecord.setValue({ fieldId: 'location', value: '' }); message.create({ title: '提示', message: '所选申请人未关联Location', type: message.Type.WARNING }).show({ duration: 5000 }); } } catch (error) { message.create({ title: '错误', message: `加载员工记录失败: ${error.message}`, type: message.Type.ERROR }).show({ duration: 5000 }); } } return { fieldChanged: fieldChanged }; });
部署与注意事项
- 在NetSuite后台创建客户端脚本,粘贴上述代码后,部署时选择**采购申请单(Requisition)**作为目标表单。
- 确保脚本拥有访问员工记录和采购申请单记录的权限。
- 代码中使用的
requestor、location是标准字段ID,若使用自定义字段,需替换为对应自定义字段ID。
内容的提问来源于stack exchange,提问作者antechf11
相关产品推荐
相关产品推荐

