问题
Continuation of my previous question: Suitescript Code stops for no apparent Reason
The child record (sublist items) are not being saved/created and linked to the parent record. The code is below.
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')
}
The field linking the child records to the main record is custrecordvpri_header
, and entered as the sublist name recmachcustrecordvpri_header
.
linecount after the for
loop is showing -1
回答1:
It looks like you are setting sublist on current client record opened on browser and you are doing submit on a 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);
来源:https://stackoverflow.com/questions/34528400/submitted-sublist-lines-on-custom-record-custom-subrecord-not-linking-to-main-re