未链接到主记录的自定义 record/custom 子记录上的已提交子列表行

Submitted sublist lines on custom record/custom subrecord not linking to main record

继续我之前的问题:

子记录(子列表项)未 saved/created 链接到父记录。代码如下。

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

看起来您正在为在浏览器上打开的当前客户端记录设置子列表,并且您正在 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);