Hello everyone, Very new to SuiteScript, but look...
# suitescript
m
Hello everyone, Very new to SuiteScript, but looking for ideas. I am trying to populate/create the Inventory Detail subrecord on a Work Order Completion transaction from the contents of a custom field. From what I have read and tried, this isn't directly possible with a Client Side Script? Any thoughts on how I could do this? I am trying to save our production line from having to click into the Inventory Detail icon to assign a Serial Number for every build. Here is the error message I get when running the below code. TypeError: Cannot find function selectNewLine in object standard subrecord Here is my code:
Copy code
/**
 *@NApiVersion 2.x
 *@NScriptType UserEventScript
 *@NModuleScope SameAccount
 */
define(['N/record'],

function(record) {
   

    function beforeSubmit(Context) {
    	
    	var CurrentWOC = Context.newRecord;
    
        var tempSNAR = CurrentWOC.getValue({
        	fieldId : 'custbodywoc_snar'});
        	
        	CurrentWOC.setValue({
        		fieldId : 'memo',
        		value   : tempSNAR,	
        	});
    	

     // Create the inventory detail subrecord.
       var subrec = CurrentWOC.getSubrecord({
              fieldId: 'inventorydetail'
       });

       // Create a line on the subrecord's inventory assignment sublist.
       subrec.selectNewLine({
              sublistId: 'inventoryassignment',
       });
       subrec.setCurrentSublistValue({
              sublistId: 'inventoryassignment',
              fieldId: 'receiptinventorynumber',
              value: '012345'
       });
       subrec.setCurrentSublistValue({
              sublistId: 'inventoryassignment',
              fieldId: 'quantity',
              value: 1
       });
       subrec.commitLine({
              sublistId: 'inventoryassignment'
       });  
    
       
    }


    return {
//        beforeLoad: beforeLoad,
        beforeSubmit: beforeSubmit,
//        afterSubmit: afterSubmit
    };
    
});
b
client script on subrecords is not supported in ss2 (https://system.netsuite.com/app/help/helpcenter.nl?fid=section_4712495741.html)
sometimes you can make it work in ss1, but i wouldnt expect it to
for you, your current error looks like you are trying to use dynamic mode methods on a standard mode record
use setSublistValue instead
m
Thanks. I can now edit the Inventory Detail via SS, but cannot seem to get around the alert: Please configure the inventory detail for the assembly item. Here is the modified code:
Copy code
/**
 *@NApiVersion 2.x
 *@NScriptType UserEventScript
 *@NModuleScope SameAccount
 */
define(['N/record'],

function(record) {
   

    function beforeSubmit(Context) {
    	
    	var CurrentWOC = Context.newRecord;
    
        var tempSNAR = CurrentWOC.getValue({
        	fieldId : 'custbodywoc_snar'});
        	
        	CurrentWOC.setValue({
        		fieldId : 'memo',
        		value   : tempSNAR,	
        	});
    	

     // Create the inventory detail subrecord.
       var subrec = CurrentWOC.getSubrecord({
              fieldId: 'inventorydetail'
       });

       // Create a line on the subrecord's inventory assignment sublist.
//       subrec.insertLine({
//              sublistId: 'inventoryassignment',
//			  line: 0
//       });
 
       subrec.setSublistValue({
              sublistId: 'inventoryassignment',
              fieldId: 'receiptinventorynumber',
			  line: 0,
              value: tempSNAR
       });
       subrec.setSublistValue({
              sublistId: 'inventoryassignment',
              fieldId: 'quantity',
			  line: 0,
              value: 1
       });
//       subrec.commitLine({
//              sublistId: 'inventoryassignment',
//			  line: 0
//       });  
    
       
    }


    return {
//        beforeLoad: beforeLoad,
        beforeSubmit: beforeSubmit,
//        afterSubmit: afterSubmit
    };
    
});
My only thought is to try to load the new record with a dummy Inventory Detail number in there to start.
b
im not sure that you can give it a default value
m
You're right. NS will not allow me to set that Before Record Load. I'm stuck.
b
i would have abandoned it at learning about subrecord support in client script