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

我的未来我决定 提交于 2019-12-23 04:45:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!