HOW TO SET SUBLIST SUB RECORD VALUES IN SUITE SCRIPT 1.0 AND 2.0

Subrecord values are retrieved and set in different ways in 1.0 and 2.0. Below examples can be used to understand the difference.

Code example for setting Sublist subrecord in 1.0.

 Note some variable have not been defined. Define them as per your accounts requirements

                      var load_inv = nlapiCreateRecord('inventoryadjustment', {recordmode: 'dynamic'});

load_inv.setFieldValue('account', '1019');

load_inv.setFieldValue('adjlocation', 106);

load_inv.setFieldText('custbody_cp_transaction', 'Coating zero parent ');

load_inv.setFieldValue('custbody_c_from', recid);

load_inv.selectNewLineItem('inventory');

load_inv.setCurrentLineItemValue('inventory', 'item', invadjitm);

load_inv.setCurrentLineItemValue('inventory', 'location', 106);

load_inv.setCurrentLineItemValue('inventory', 'adjustqtyby', 1);

var subrec = load_inv.createCurrentLineItemSubrecord('inventory', 'inventorydetail');


subrec.selectNewLineItem('inventoryassignment');

subrec.setCurrentLineItemText('inventoryassignment', 'issueinventorynumber',invnum);


subrec.setCurrentLineItemValue('inventoryassignment', 'binnumber',orgbin);

subrec.setCurrentLineItemValue('inventoryassignment', 'quantity',onhand);

subrec.commitLineItem('inventoryassignment');


subrec.commit();

load_inv.commitLineItem('inventory');

nlapiSubmitRecord(load_inv, false, true);



Code example for setting Sublist subrecord in 2.0





define([ 'N/record' ],


 function(record) { function afterSubmit(context)

 { // Create the purchase order.

 var rec = record.create({ type: record.Type.PURCHASE_ORDER, isDynamic: true });

 rec.setValue({ fieldId: 'entity', value: '1663' });

 rec.setValue({ fieldId: 'location', value: '6' }); // Create one line in the item sublist. 

rec.selectNewLine({ sublistId: 'item' }); 

rec.setCurrentSublistValue({ sublistId: 'item', fieldId: 'item', value: '299' }); 

rec.setCurrentSublistValue({ sublistId: 'item', fieldId: 'quantity', value: 1 }); 

var subrec = rec.getCurrentSublistSubrecord({ sublistId: 'item', fieldId: 'inventorydetail' }); 
// Add a line to the subrecord's inventory assignment sublist.

 subrec.selectNewLine({ sublistId: 'inventoryassignment' });

 subrec.setCurrentSublistValue({ sublistId: 'inventoryassignment', fieldId: 'quantity', value: 2 }); 

subrec.setCurrentSublistValue({ sublistId: 'inventoryassignment', fieldId: 'receiptinventorynumber', value: '01234' });

 // Save the line in the subrecord's sublist. 

subrec.commitLine({ sublistId: 'inventoryassignment' }); // Save the line in the record's sublist rec.commitLine({ sublistId: 'item' }); 

var recId = rec.save(); // Save the record. 

 var recId = rec.save(); 





Comments

  1. We are NetSuite Solution Provider with vast experience in NetSuite Implementation, netsuite customization including netsuite training & netsuite integration.
    NetSuite Solution Provider
    NetSuite Training
    NetSuite Implementation
    NetSuite Customization
    NetSuite Integration

    ReplyDelete
  2. Good article, how we can update the existing record
    line.

    ReplyDelete

Post a Comment

Popular posts from this blog

Work Around the 1000 Row Limit Returned by Saved Searches in Netsuite

Understand Core Technology behind SuiteScript 2.0