【问题标题】:Submitted sublist lines on custom record/custom subrecord not linking to main record自定义记录/自定义子记录上提交的子列表行未链接到主记录
【发布时间】:2015-12-30 11:13:25
【问题描述】:

我上一个问题的继续:Suitescript Code stops for no apparent Reason

子记录(子列表项)未保存/创建并链接到父记录。代码如下。

try {
    var vendorid = nlapiGetRecordId();              console.dir('Vendor ID: #'+vendorid);
    var vprRecordID = create_VPR_record(vendorid);  console.dir('Record Created: #'+vprRecordID);
    var newVprRecord = nlapiLoadRecord('customrecordvendorpricereview', vprRecordID);
    var vendorItems = getVendorItems(vendorid);
    var numberItems = vendorItems.length;
    for (var i=1; i<numberItems; i++ ) {
        newVprRecord.selectNewLineItem(SUBLIST_Items);
        var itemID = parseInt(vendorItems[i].getId());
        var iType = itemType(itemID);
        newVprRecord.setCurrentLineItemValue(SUBLIST_Items,'custrecordvpri_item',itemID);
        var avgCost  = Round(nlapiLookupField(iType,itemID,'averagecost'),4);
        var stdCost  = Round(nlapiLookupField(iType,itemID,'custitem_costrepl'),4);
        var lastCost = Round(nlapiLookupField(iType,itemID,'lastpurchaseprice'),4);
        if (isNaN(avgCost))  { avgCost  = '' };
        if (isNaN(stdCost))  { stdCost  = '' };
        if (isNaN(lastCost)) { lastCost = '' };
        newVprRecord.setCurrentLineItemValue(SUBLIST_Items,'custrecordvpri_costavg',  avgCost );
        newVprRecord.setCurrentLineItemValue(SUBLIST_Items,'custrecordvpri_costlast', lastCost );
        newVprRecord.setCurrentLineItemValue(SUBLIST_Items,'custrecordvpri_coststd',  stdCost );
        newVprRecord.setCurrentLineItemValue(SUBLIST_Items,'custrecordvpri_vendorcurrency',vendorItems[i].getValue('vendorpricecurrency'));
        newVprRecord.setCurrentLineItemValue(SUBLIST_Items,'custrecordvpri_currentprice',vendorItems[i].getValue('vendorcost'));
        newVprRecord.commitLineItem(SUBLIST_Items);
        log('Commit Line #'+i+'  Item ID: '+itemID+'  '+vendorItems[i].getValue('itemid'));
    }
    var linecount = newVprRecord.getLineItemCount(SUBLIST_Items);   console.dir('Line Count #'+linecount );
    nlapiSubmitRecord(newVprRecord);  console.dir('Resubmitting Record #'+vprRecordID+'\n\n'+newVprRecord );
    var url = nlapiResolveURL('record', 'customrecordvendorpricereview', vprRecordID, 'edit');
    window.open(url, "New Vendor Price Review");
} catch (err) { 
    logError(err,'Create_VPR_Main')
}

将子记录链接到主记录的字段是custrecordvpri_header,输入为子列表名称recmachcustrecordvpri_header。

for 循环后的行数显示为 -1

【问题讨论】:

  • 我知道我的代码有点凌乱,但一旦我得到它的关键功能,我会解决这个问题。
  • 子记录中也没有创建“子”记录。我目前没有使用 nlapiAttachRecord,它的成本为 10 点,所以我希望有另一种方法来链接它们。
  • 您的意思是您已将自定义子列表应用于标准供应商记录,并且使用子列表 API 您无法将其记录插入供应商?
  • “父”记录是customrecordvendorpricereview,该记录的父是供应商,因此这些行不直接链接到标准供应商记录
  • 您在哪种记录类型上运行此客户端脚本?看起来您正在在浏览器上打开的当前客户记录上设置子列表,并且您正在 nlobjRecord 上提交。

标签: netsuite suitescript


【解决方案1】:

看起来您正在在浏览器上打开的当前客户端记录上设置子列表,并且您正在提交 nlobjRecord

//This is the nlobjRecord

var newVprRecord = nlapiLoadRecord('customrecordvendorpricereview', vprRecordID);

//To set line items on this record use :
newVprRecord.selectNewLineItem(SUBLIST_Items);
...
//to set line item value use
newVprRecord.setCurrentLineItemValue(SUBLIST_Items,'custrecordvpri_costavg',  avgCost);
...
//to commit use 
newVprRecord.commitLineItem(SUBLIST_Items);
...
//finally after line items loop is done
nlapiSubmitRecord(newVprRecord,true);

【讨论】:

  • 好的,它正在循环遍历行,行数现在正确(在此供应商的情况下为 8)。但是当它到达提交记录时,它会产生一个错误:Invalid custrecordvpri_item reference key 16325。 custrecordvpri_item 是项目的子列表字段 ID,它是 item 的列表/记录类型。我尝试插入 itemid,它给出了同样的错误。
  • 我将修改主要问题中的代码,使其包含当前(新)代码。
  • 我想我可能已经找到了错误的原因...有问题的项目被标记为 inactive 所以我将在项目搜索中添加非活动过滤器并重新测试。
  • 这是删除非活动项目的正确过滤器吗? filters[0] = new nlobjSearchFilter('isinactive', null, 'is', 'F' ) 因为我仍然在结果中获得非活动项目
  • 一定是打错字了.....一切正常!!!!!!!!!非常感谢你的帮助,只希望我能在你的答案上打上十几次!!!!
猜你喜欢
  • 1970-01-01
  • 2016-02-27
  • 1970-01-01
  • 2018-10-13
  • 1970-01-01
  • 1970-01-01
  • 2013-01-09
  • 1970-01-01
  • 2016-11-04
相关资源
最近更新 更多