Hi, I am trying to create a deposit application in...
# suitescript
r
Hi, I am trying to create a deposit application in SuiteScript, I tried using it by record.transform from Customer Deposit and also record.create but I am getting ZERO on the getLineCount but I am seeing more than 1 invoice in the UI. Thank you for helping!
b
r
Thank you for this @battk, I try to use again record.transform for this but I am still getting ZERO value on the getLineCount from the 'apply' sublist I have also confirmed that the internal IDs used in the transform is correct.
Copy code
// Transform the Customer Deposit into a Deposit Application
                    var depositAppRec = record.transform({
                        fromType: record.Type.CUSTOMER_DEPOSIT,
                        fromId: depositId,
                        toType: record.Type.DEPOSIT_APPLICATION,
                    });
                    var sublists = depositAppRec.getSublists();
                    log.debug('Available Sublists', sublists);

                    // Loop through the 'apply' sublist to find the correct invoice
                    var lineCount = depositAppRec.getLineCount({sublistId: 'apply'});
                    log.debug('lineCount',lineCount);
                    for (var i = 0; i < lineCount; i++) {
                        var appliedInvoiceId = depositAppRec.getSublistValue({
                            sublistId: 'apply',
                            fieldId: 'internalid',
                            line: i
                        });
                        log.debug("appliedInvoiceId",appliedInvoiceId);
                        log.debug("invoiceId",invoiceId);
                        if (appliedInvoiceId == invoiceId) {
                            // depositAppRec.selectLine({ sublistId: 'apply', line: i });

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

                            depositAppRec.setSublistValue({
                                sublistId: 'apply',
                                fieldId: 'amount',
                                value: amountToApply,
                                line : i
                            });

                            // depositAppRec.commitLine({ sublistId: 'apply' });

                            log.debug('Invoice Applied', 'Invoice ID: ' + invoiceId + ', Applied Amount:' + amountToApply);
                            break; // Stop loop after applying the correct invoice
                        }
                    }

                    var depositAppId = depositAppRec.save();
b
you arent reading the docs closely enough
its telling you a recomended way to create deposit applications
your attempt is not attempting to do what it recommends
r
Okay, I see it now. Thank you for pointing it out.