The internal id of all the bill credits applied in a bill payment record cannot be retrived easly from record object and by using saved search.
Upon checking it was noticed that an enhancement has been created for this functionality: “Enhancement 213645: Search to show all Bills and Bill Credits associated to a Bill Payment”.
Which means showing the information of the Bill Payment’s Credits Applied Sublist in a Saved Search is currently a limitation of NetSuite.
We cannot create a Saved Search for Bill Payments and show the applied Credits as there is no available field we can use in a Search.
As a solution for getting all internal id of the applied Bill Credits in the Bill Payment record we can use SuiteQL query.
Add N/query module in script.
const getInputData = (inputContext) => {
try {
let billPaymentRecordId = runtime.getCurrentScript().getParameter({ name: ‘custscript_jj_bill_payment_id’ });
let creditAppliedId = getBillPaymentCredits(billPaymentRecordId);
return [
JSON.stringify({
creditAppliedId: creditAppliedId
})
];
} catch (e) {
log.error(‘Error in getInputData’, e.message);
return [];
}
}
function getBillPaymentCredits(billPaymentId) {
let queryResults = query.runSuiteQL({
query: `
SELECT
Applied.nextdoc as billCreditId
FROM
AppliedCreditTransactionLineLink as Applied
WHERE
Applied.paymenttransaction = ${billPaymentId}
`
});
let results = queryResults.asMappedResults();
// Map the results to an array of billCreditId values
let billCreditIds = results.map(result => result.billcreditid);
return billCreditIds;
}