Hi guys, I created a scheduled script to transform...
# suitescript
g
Hi guys, I created a scheduled script to transform a vendor bill into a vendor payment, I want to apply the payment for more than one vendor bill but it is only applied to the vendor bill that I'm transforming. See my code below:
Copy code
var paymentRecord = record.transform({
                    fromType: record.Type.VENDOR_BILL,
                    fromId: vendorBillId,
                    toType: record.Type.VENDOR_PAYMENT,
                    isDynamic: false
                });
                var numLines = paymentRecord.getLineCount({
                    sublistId: 'apply'
                });
                var facturasMemo = '';
                for(var i=0; i < numLines; i++){
                    var paymentVendorBill = paymentRecord.getSublistValue({
                        sublistId: 'apply',
                        fieldId: 'doc',
                        line: i
                    });
                    for( var j = 0; j < arrOpenBillsCount; j++){
                        if(scriptObj.getRemainingUsage() < 100){
                            log.error('poWithErrors', poWithErrors);
                            if(poWithErrors.length > 29){
                                sendErrorEmail(emailAuthor, recipientEmail, poWithErrors);
                            }
                            return 
                        }

                        paymentRecord.setSublistValue({
                            sublistId: 'apply',
                            fieldId: 'apply',
                            line: i,
                            value: false
                        });

                        if(paymentVendorBill != arrOpenBills[j].getValue({ name: 'internalid'})){
                            continue;    
                        }
                        
                        log.debug('paymentVendorBill=' + paymentVendorBill);
                        paymentRecord.setSublistValue({
                            sublistId: 'apply',
                            fieldId: 'apply',
                            line: i,
                            value: true
                        });
                        facturasMemo += 'Factura #' + arrOpenBills[j].getValue({ name: 'tranid'}) + ',';
                    }
                    
                }
I don't know why the apply sublist field is not set to true, but the facturasMemo variable is being concatenated correctly. Do you know if it is possible to do this?
c
Can you do this in the UI, is the usual question?
b
its the way the code is written
specifically each iteration of your nested loop sets apply to false
so only the last iteration of the loop really matters
👍 1
g
You're right @battk, thank you so much for your help.
s
I avoid writing loops, especially nested ones, whenever possible.
life is much better.