Anyone have netsuite give you syntax errors even t...
# suitescript
s
Anyone have netsuite give you syntax errors even though their editor says otherwise? It says im missing a
;
after my for loop initializer but i dont see it. Im using VS Code and it doesnt see any syntax errors
define(['N/record','N/log'], function (record, log) {
    
function beforeSubmit(context){
        
var objRecord = context.newRecord; //Create object
        
var estBodyShipDate = objRecord.getText('custbody_estimated_ship_date');//get text of date
        
var numLineItems = objRecord.getLineCount({sublistId: 'item'});
        
for (let index = 0; index < numLineItems; index++){
            
updateLine(objRecord, index, estBodyShipDate);
            
log.debug({
                
"title": "For Loop Debug",
                
"details": "Line " + index + " updated."
            
});
        
}
    
}
    
function updateLine(objRecord, index, estBodyShipDate){
        
objRecord.selectLine({
            
sublistId: "item",
            
line: index
        
});
        
objRecord.setCurrentSublistValue({
            
sublistId: "item",
            
fieldID: "expectedshipdate",
            
value: estBodyShipDate
        
});
        
objRecord.commitLine({sublistId: "item"});
    
}
    
return {
        
beforeSubmit : beforeSubmit
    
}
});
👀 1
w
Could maybe it doesn't like that you have quotes around the log.debug parameter names or that you use let in the for loop initialization. Is it ss2.1?
s
using 2.0 i believe. Never had that issue with adding quotes there
it was the
let
s
don't write loops?
s
@stalbert i need to step through each line item and change column value. What do you suggest?
s
I suggest using lodash (e.g. _.map() ) and NFT. I almost never write loops by hand in SuiteScript.
what record type is this code being used on?
s
sale orders
s
With NFT it would be as simple as this
s
Interesting. Ill look into it more. thanks for the example