Has anyone try to get value on sublist via loop? I...
# suitescript
t
Has anyone try to get value on sublist via loop? I am using the following to get the value but I'm receiving this error. Not sure why "TypeError: Cannot read property 'getSublistValue' of undefined"
var itemRecord = [];
            
const estimateRec = context.currentRecord;
const currLineItem = estimateRec.*getLineCount*({sublistId: estimateCfg.ESTIMATE_FLDS.ESTIMATE_ITEM});
            
log.*debug*('storeLineItemVal', currLineItem- 1);
            
for (var i = 0; i <= count - 1; i++) {
                
log.*debug*('storeLineItemVal_i', i);
                
const getLineItemId = estimateRec.*getSublistValue*({
                    
sublistId: estimateCfg.ESTIMATE_FLDS.SUBLIST.SBLST_ITEM,
                    
fieldId: estimateCfg.ESTIMATE_FLDS.ESTIMATE_ITEM,
                    
line: i
                
});
                
itemRecord.*push*(getLineItemId);
                
log.*debug*('itemRecord', itemRecord);
            
}
s
If your goal is an array of item ids from the
item
sublist, it's as simple as this (NFT):
Copy code
const e = new Estimate(context.currentRecord)
const itemRecord = _.map(e.item, line=> line.item)
e
count is not defined...
t
hi @stalbert, can you explain the use of "_"
@Eric B i declare it as param on my function
s
"_" is lodash
👍 1
notably, the approach I mention above only has a few characters of code you write:
line => line.item
so very little room for bugs. Then again, it's also only two lines of code to do all the stuff your example was trying to do in a more convoluted way.
t
ok i think I got your point here @stalbert.. BTW i fix the issue I used the same code with few tweaks
s
that's both great and unfortunate!
b
the more traditional looping convention is to do
Copy code
for (var i = 0; i < count; i++) {