NetSuite 地址字段自动创建

问题描述 投票:0回答:0

我正在尝试编写一个 afterSubmit 入口点,自动填充新 Leads 表单上地址字段的子列表和子记录。我可以使用 record.load 更改当前地址,但如果当前不存在地址(新线索总是这种情况)并且我正在尝试运行 record.create,则什么也不会发生。

/**

  • @NApiVersion 2.x

  • @NScriptType UserEventScript */

    define([ 'N/record' ],函数(记录){ 提交后的功能(上下文){

     // Create the record.
     var rec = record.create({
         type: record.Type.LEAD,
         isDynamic: true
     });
    
    
    
     // Create a line in the Address sublist.
     rec.selectNewLine({
         sublistId: 'addressbook'
     });
    
     // Set an optional field on the sublist line.
     rec.setCurrentSublistValue({
         sublistId: 'addressbook',
         fieldId: 'label',
         value: 'Primary Address'
     });
    
     // Create an address subrecord for the line.
     var subrec = rec.getCurrentSublistSubrecord({
         sublistId: 'addressbook',
         fieldId: 'addressbookaddress'
     });
    
     // Set body fields on the subrecord. Because the script uses 
     // dynamic mode, you should set the country value first. The country 
     // value determines which address form is to be used, so by setting
     // this value first, you ensure that the values for the rest 
     // of the form's fields will be set properly.
     subrec.setValue({
         fieldId: 'country',
         value: 'US'
     });
    
     subrec.setValue({
         fieldId: 'city',
         value: 'San Mateo'
     });
    
     subrec.setValue({
         fieldId: 'state',
         value: 'CA'
     });
    
     subrec.setValue({
         fieldId: 'zip',
         value: '94403'
     });
    
     subrec.setValue({
         fieldId: 'addr1',
         value: '2955 Campus Drive'
     });
    
     subrec.setValue({
         fieldId: 'addr2',
         value: 'Suite 100'
     });
    
     // Save the sublist line.
     rec.commitLine({
         sublistId: 'addressbook'
     });
    
     // Save the record.
     try{
         var recId = rec.save();
    
         log.debug({
             title: 'Record created successfully',
             details: 'Id: ' + recId
         });
     } catch (e){
         log.error({
             title: e.name,
             details: e.message
         });
     }
    

    } 返回 { 提交后:提交后 }; });

javascript netsuite
© www.soinside.com 2019 - 2024. All rights reserved.