简体   繁体   English

SuiteScript - removeLine 不删除最后一行

[英]SuiteScript - removeLine not removing last line

I have created a pageInit SuiteScript that should remove line items on a Sales Order if they have a custom field filled out.我创建了一个 pageInit SuiteScript,如果他们填写了自定义字段,则应该删除销售订单上的行项目。 The issue I am having is that it will not remove the line if it is the last line and no other line has a value for loss.我遇到的问题是,如果它是最后一行并且没有其他行具有损失值,它将不会删除该行。

function pageInit(context) {

    var objRec = context.currentRecord;

    var itemsLength = objRec.getLineCount({
        sublistId: 'item'
    });

    for (var i = itemsLength-1; i >= 0; i--){
        var loss = objRec.getSublistValue({
            sublistId: 'item',
            fieldId: 'custcol_linelossreason',
            line: i
        });

        if (loss) {
            objRec.removeLine({
                sublistId: 'item',
                line: i,
                ignoreRecalc: true
            });
            log.debug('removed', 'Line ' + i + ' has been removed.');
        } else {
            log.debug('no removal', 'Line ' + i + ' will remain.');
        }
    }

The only thing I can find is that maybe that line is missing the loss value...?我唯一能找到的是那条线可能缺少损失值......? I tested with your code, minus the loss piece and it worked perfectly.我用你的代码进行了测试,减去了损失部分,它工作得很好。 Below is what I tried with.下面是我尝试过的。

**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 * @NModuleScope SameAccount
 * 
 */
define(['N/record'],function(record){
  function pageInit(context){
    var objRec=context.currentRecord;
    var itemsLength=objRec.getLineCount({
      sublistId:'item'
    });
    log.debug('itemsLength',itemsLength);
    for(var i=itemsLength-1;i>=0;i--){
      log.debug('running line ',i+' of '+itemsLength);
      /*
      var loss=objRec.getSublistValue({
        sublistId:'item',
        fieldId:'custcol_linelossreason',
        line: i
      });
      */
      //if(loss){
      objRec.removeLine({
        sublistId:'item',
        line:i,
        ignoreRecalc:true
      });
      log.debug('removed','Line '+i+' has been removed.');
     /*
      }else{
        log.debug('no removal','Line '+i+' will remain.');
      }
      */
    }
  }

  return{
    pageInit:pageInit
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM