【问题标题】:NetSuite Invoice from Case案例中的 NetSuite 发票
【发布时间】:2021-08-21 00:39:48
【问题描述】:

希望有人能够帮助我解决我收到的这个错误...我正在使用案例记录上的自定义按钮,该按钮将使用案例中的字段创建发票。我有一个自定义字段,它是案例中可能需要的所有项目的多项选择。并非所有案例都需要一个项目,因此我将在逻辑或工作流程中进行编码,以防止在未选择项目时显示按钮,并锁定编辑并将案例状态标记为已开票,并在创建发票后处于关闭阶段从记录。我的问题是,在测试套件时,我在尝试设置附属字段和部门时遇到错误。这是我的错误:["type":"error.SuiteScriptError"."name":"INVALID_FLD_VALUE", "message":"您为以下字段输入了无效的字段值 2:subscription"

我正在测试的客户被分配了内部 ID 为 2 的子公司

下面是我的代码的一部分,我尝试删除子值中的引号,并尝试使用当前的 record.getValue 设置辅助值。两者都抛出相同的错误

`请求函数(上下文){

var custom_id= context.request.parameters.custom_id; var currentRecord record.load({ type: record.Type.SUPPORT CASE,

id:custom_id

});

var newRecord = record.create({ type: record.Type.INVOICE,

isDynamic: 真

});

newRecord.setValue({ fieldId: 'customform',

值:122'

});

newRecord.setValue({

fieldId: '实体',

值:currentRecord.getValue('entity')

});

newRecord.setValue({ fieldId: 'otherrefnum',

值:currentRecord.getValue('casenumber')

});

newRecord.setValue({

fieldId:'附属',值:'2'

});

newRecord.setValue({ fieldId: '部门',

值:'17'

});

newRecord.selectNewLine({ sublistId: 'item'

});

newRecord.setCurrent SublistValue(( sublistId:

'item', fieldId: 'item',

//值:46

值:currentRecord.getValue('custevent_multi_select_work_orders')

});

newRecord.setCurrentSublistValue({ sublistId: 'item',

fieldId: '数量',

值:'1'

}); ` 非常感谢任何帮助!

【问题讨论】:

    标签: netsuite suitescript suitescript2.0


    【解决方案1】:

    我发现的错误:

    • 加载支持案例记录时出现拼写错误。应该是 SUPPORT_CASE
    var currentRecord = record.load({ 
       type: record.Type.SUPPORT_CASE,
       id: custom_id
    });
    
    • 这里有很多错别字,比如一个引号,希望你仔细看看
    newRecord.setValue({ 
       fieldId: 'customform',
       value: 122'
    });
    
    • 关于您的主要附属问题,您正在使用引号传递值 (2)。尝试在没有这些的情况下通过它
    newRecord.setValue({
       fieldId: 'subsidiary', 
       value: 2
    });
    

    newRecord.setValue({
       fieldId: 'subsidiary', 
       value: Number(2)
    });
    

    仅使用逗号来传递字符串值。对于数值,不要使用它们。

    尝试这些更改,如果问题仍然存在,请告诉我,这个错误有很多可能性!

    【讨论】:

      【解决方案2】:

      我知道这并不完全是您所需要的,但它功能齐全,您可以进行自定义/挑选要使用的部件。这是我过去用来从案例记录创建销售订单的自定义函数。祝你好运!

      /**
       * case_createSOButton.js
       * @NApiVersion 2.x
       * @NScriptType ClientScript
       */
      
      define (['N/record', 'N/currentRecord'],
          function (record, currentRecord){
      
          //NetSiuite requires the existence of 1 of their functions
          function pageInit(context) {
            var currentRecord = context.currentRecord;
          }
          
          //Button function to create a Sales order and indicate on the Case record the new Sales Order record
          //in the UI on the Script record add this function name to the "Buttons" section
          function createSO(){
            log.audit('function started', 'Cases - Service Case CS createSO');
            var caseRecord = currentRecord.get();
      
            //if record is in create mode than do not allow creation of a Sales Order
            //mode property is not available, so base it off of id properrty.  ids dont exist until record is saved
            var caseId = caseRecord.id;
            if (!caseId){
              alert('You cannot create a Sales Order while creating a new Case.\nPlease save the Case, then try again.');
              return;
            }
      
            //if sales order already exists, do not allow creation of a new SO
            var associatedSO = caseRecord.getValue({fieldId: 'custevent_case_associated_sales_orde'});
            if (associatedSO){
              alert('Cannot create a Sales Order since "Associated Sales Order" already exists.');
              return;
            }
      
            //gather info from user
            var memo = prompt("What's the reason for the charge?\nThe text below will be copied onto the Sales Order \"Memo\" field.");
            //if user clicks cancel, do not continue
            if (memo == null){
              return;
            }
            var description = prompt("Enter a description for the Service Work Item.");
            //if user clicks cancel, do not continue
            if (description == null){
              return;
            }
            var amount = prompt("Enter an amount for the Service Work Item.\nPlease only enter #s, no letters, decimal/cents optional.");
            //if user clicks cancel or there's no # value found, do not continue
            var hasNumber = /\d/;  //validation for confirming the amount variable is a number
            hasNumber = hasNumber.test(amount);
            if (amount == null){
              return;
            }
            if(hasNumber == false){
              alert('No numbers found in entry, please try again.');
              return;
            }
            alert('Please wait for the process to complete before closing this page.');
      
            //declare static values
            var customform = 199;
            var subsidiary = 2; 
            var status = 3;
            var specialist = 62736;
            var channel = 181; 
            var totalKW = 0; 
            var lenderPoints = 0; 
            var today = new Date();
            var itemId = 3566;
            var lender = 10;
            var loanProduct = 37;
      
            //load customer to gather values
            var entity = caseRecord.getValue({fieldId: 'company'});
            var customerRec = record.load({type: record.Type.CUSTOMER, id: entity});
            var location = customerRec.getValue({fieldId: 'custentity_customer_market'})|| null;
            var job = caseRecord.getValue({fieldId: 'custevent_case_associated_project'});
      
            //load associated project to gather values
            var projectRec = record.load({type: record.Type.JOB, id: job});
            var projectMgr = projectRec.getValue({fieldId: 'custentity_project_manager_customer'})|| null;
            var engineer = projectRec.getValue({fieldId: 'custentity31'})|| null;
            var installMgr = projectRec.getValue({fieldId: 'custentity_install_manager'})|| null;
            var state = projectRec.getValue({fieldId: 'custentity_csegmarke'})|| null;
            var region = projectRec.getValue({fieldId: 'custentity_cseg2'})|| null;
            var market = projectRec.getValue({fieldId: 'custentity_cseg3'})|| null;
      
            //create SO record, set values
            var newSORec = record.create({type: record.Type.SALES_ORDER, isDynamic: true});
            newSORec.setValue({fieldId: 'customform', value: customform, ignoreFieldChange: false});
            newSORec.setValue({fieldId: 'entity', value: entity});
            newSORec.setValue({fieldId: 'job', value: job});
            newSORec.setValue({fieldId: 'custbody_sostatus', value: status});
            newSORec.setValue({fieldId: 'custbody_total', value: totalKW});
            newSORec.setValue({fieldId: 'custbody13', value: lenderPoints});
            newSORec.setValue({fieldId: 'custbody_fundingissues', value: memo});
            newSORec.setValue({fieldId: 'subsidiary', value: subsidiary});
            newSORec.setValue({fieldId: 'custbody_finance_specialist', value: specialist});
            newSORec.setValue({fieldId: 'saleseffectivedate', value: today});
            newSORec.setValue({fieldId: 'custbody_cseglende', value: lender});
            newSORec.setValue({fieldId: 'custbody_csegloan', value: loanProduct});
            newSORec.setValue({fieldId: 'custbody_project_manager', value: projectMgr});
            newSORec.setValue({fieldId: 'custbody_engineer', value: engineer});
            newSORec.setValue({fieldId: 'custbody_installmgr', value: installMgr});
            newSORec.setValue({fieldId: 'class',  value: channel, forceSyncSourcing: true});
            newSORec.setValue({fieldId: 'custbody_csegmarke', value: state, forceSyncSourcing: true});
            newSORec.setValue({fieldId: 'custbody_cseg2', value: region, forceSyncSourcing: true});
            newSORec.setValue({fieldId: 'custbody_cseg3', value: market, forceSyncSourcing: true});
            newSORec.setValue({fieldId: 'location', value: location, forceSyncSourcing: true});
      
            //set default line item(s)
            newSORec.selectLine({sublistId: 'item', line: 0});
            newSORec.setCurrentSublistValue({sublistId: 'item', fieldId: 'item', value: itemId, ignoreFieldChange: false});
            newSORec.setCurrentSublistValue({sublistId: 'item', fieldId: 'description', value: description, ignoreFieldChange: false});
            newSORec.setCurrentSublistValue({sublistId: 'item', fieldId: 'rate', value: parseInt(amount), ignoreFieldChange: false});
            newSORec.commitLine({sublistId: 'item'});
      
            //save new SO
            var newSORecId = newSORec.save({enableSourcing: true, ignoreMandatoryFields: false});
      
            //add SO Rec to Case
            record.submitFields({
              type: record.Type.SUPPORT_CASE,
              id: caseRecord.id,
              values: {
                custevent_case_associated_sales_orde: newSORecId
              },
              options: {
                //enableSourcing: false,  //default is true
                ignoreMandatoryFields : true //default is false
              }
            });
      
            //alert user when SO is created and open in a new tab
            alert("The new Sales Order will open in a new tab. \n*Reminder - to save this record if you've made changes.");
            var url = 'https://1234567.app.netsuite.com/app/accounting/transactions/salesord.nl?id='+newSORecId
            window.open(url, '_blank');
            log.audit('function end', 'Cases - Service Case CS createSO');
          }//end of create SO funciton
      
              return {
            pageInit: pageInit,
                  createSO: createSO
              }
          }
      );
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-05-24
        • 1970-01-01
        • 2020-10-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多