延續我以前的問題: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
。
linecount的for
循環後顯示-1
我知道我的代碼是有點不整潔,但我會解決,一旦我得到它的功能關鍵。 –
在子記錄中也沒有創建「子」記錄。我目前沒有使用nlapiAttachRecord,它有10點的成本,所以我希望有另一種方式來鏈接它們。 –
您的意思是您已將自定義子列表應用於標準供應商記錄並使用子列表API無法將其記錄插入供應商? – prasun