Hi, How to remove/update sublist lines in record.t...
# suitescript
m
Hi, How to remove/update sublist lines in record.transform, please have a look at below code
Copy code
try {
                
                var currentRecord = context.currentRecord;                
                var purchaseOrderId = currentRecord.getSublistValue({ sublistId: 'expense', fieldId: 'orderdoc', line: 0 });                
                if (purchaseOrderId) {
                    
                    var lineCount = currentRecord.getLineCount({ sublistId: 'expense' });
                    
                    var TR_RECORD = record.transform({
                        fromType: record.Type.PURCHASE_ORDER,
                        fromId: purchaseOrderId,
                        toType: record.Type.ITEM_RECEIPT
                    });                    

                    for (var i = 0; i < lineCount; i++) { 
					
                        //how do i replace and delete lines which is not exist in currentRecord?   
						
                        var orderDoc = currentRecord.getSublistValue({ sublistId: 'expense', fieldId: 'orderdoc', line: i });
                        var orderLine = currentRecord.getSublistValue({ sublistId: 'expense', fieldId: 'orderline', line: i });
                        var account = currentRecord.getSublistValue({ sublistId: 'expense', fieldId: 'account', line: i });
                        var amount = currentRecord.getSublistValue({ sublistId: 'expense', fieldId: 'amount', line: i });                       
                        TR_RECORD.setSublistValue({
                            sublistId: 'expense',
                            fieldId: 'category',
                            line: lineCount[i],
                            value: expanseAccount
                        });
                    }
                    var idl = TR_RECORD.save({
                        enableSourceing: true
                    });                    
                }				
            }
            catch (err) {
                dialog.alert({
                    title: 'Vendor Bill',
                    message: err.message
                });
            }
s
Never name a variable the same as a Netsuite module. var currentRecord = context.currentRecord is very confusing behavior since it now overwrites
N/currentRecord
Also this does not make much sense
line: lineCount[i],
, lineCount is just a number
expanseAccount
also does not exist here, so its possible it is the problem
m
How do i remove and add lines any idea
s
What did you try to do...
N/record
has
removeLine
and
setSublistValue
should work, assuming you've fixed/addressed any potential problems
b
I would expect both adding or removing lines from an item receipt to fail
Its not an operation you would do in the ui
m
@battk Thanks for you information, How do i receive only those items which is exist in the currentRecord?
can i create new item receipts and then i can add items in it?
b
Figure out how to add/remove items in an item receipt via the ui
Whatever fields you set / unset in the ui are the same you would do in script