Fetching the credit Sublist values From Payment record.

The credit sublist values are not directly accessible using a script. However, we can create a workbook to fetch the credit data, and then use SQL to retrieve it in the script.

Steps:

Create a dataset for the required data. Navigate to Analytics > create new dataset.

We can filter the results by adding criteria.

After creating the dataset Click on the create workbook option:

Click on add all feilds to workbook option:

The columns will be added to the workbook now:

Click on save & save the workbook.

Use the export as script option to get the SQL after saving the workbook:

The SQL can be copied and can be used in script (similar to exporting saved serach).

Script part:

Here the internal id of the payment should be passed to the function as transactionId:

        /**
       * Function to get credit data using SQL query
       * @param {string} transactionId 
       * @returns {Array}
       */
        function getCreditData(transactionId) {
            try{
                let sql = "SELECT BUILTIN_RESULT.TYPE_DATE(AppliedCreditTransactionLineLink_SUB.trandate) AS trandate, BUILTIN_RESULT.TYPE_STRING(BUILTIN.DF(AppliedCreditTransactionLineLink_SUB.nexttype)) AS nexttype, BUILTIN_RESULT.TYPE_STRING(BUILTIN.DF(AppliedCreditTransactionLineLink_SUB.nextdoc)) AS nextdoc, BUILTIN_RESULT.TYPE_STRING(BUILTIN.DF(AppliedCreditTransactionLineLink_SUB.previousdoc)) AS previousdoc, BUILTIN_RESULT.TYPE_CURRENCY(BUILTIN.CONSOLIDATE(AppliedCreditTransactionLineLink_SUB.foreignamount, 'INCOME', 'NONE', 'DEFAULT', 0, 0, 'DEFAULT'), BUILTIN.CURRENCY(BUILTIN.CONSOLIDATE(AppliedCreditTransactionLineLink_SUB.foreignamount, 'INCOME', 'NONE', 'DEFAULT', 0, 0, 'DEFAULT'))) AS foreignamount FROM TRANSACTION, (SELECT AppliedCreditTransactionLineLink.paymenttransaction AS paymenttransaction, AppliedCreditTransactionLineLink.paymenttransaction AS paymenttransaction_join, transaction_0.trandate AS trandate, AppliedCreditTransactionLineLink.nexttype AS nexttype, AppliedCreditTransactionLineLink.nextdoc AS nextdoc, AppliedCreditTransactionLineLink.previousdoc AS previousdoc, AppliedCreditTransactionLineLink.foreignamount AS foreignamount FROM AppliedCreditTransactionLineLink, TRANSACTION transaction_0 WHERE AppliedCreditTransactionLineLink.nextdoc = transaction_0.ID(+) ) AppliedCreditTransactionLineLink_SUB WHERE TRANSACTION.ID = AppliedCreditTransactionLineLink_SUB.paymenttransaction(+) AND TRANSACTION.ID = ? ";
                let results = query.runSuiteQL({
                    query: sql,
                    params: [transactionId]
                });
                return results.asMappedResults();
            }catch(e){
                log.error("error@getCreditData",e);
            }
        }

Leave a comment

Your email address will not be published. Required fields are marked *