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

时间:2015-12-30 11:13:25

标签: netsuite suitescript

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

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

CCP

将子记录链接到主记录的字段为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循环显示-1

之后的行数

1 个答案:

答案 0 :(得分: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);