function transformBillToPayment(billId, journalId, incomeTaxAmount) {
try {
let payment = record.transform({
fromType: record.Type.VENDOR_BILL,
fromId: billId,
toType: record.Type.VENDOR_PAYMENT,
isDynamic: true
});
let applyLineCount = payment.getLineCount({ sublistId: ‘apply’ });
for (let i = 0; i < applyLineCount; i++) {
payment.selectLine({ sublistId: ‘apply’, line: i });
payment.setCurrentSublistValue({
sublistId: ‘apply’,
fieldId: ‘apply’,
value: false
});
payment.commitLine({ sublistId: ‘apply’ });
}
for (let i = 0; i < applyLineCount; i++) {
let type = payment.getSublistValue({ sublistId: ‘apply’, fieldId: ‘type’, line: i });
let docId = payment.getSublistValue({ sublistId: ‘apply’, fieldId: ‘doc’, line: i });
payment.selectLine({ sublistId: ‘apply’, line: i });
if (type === ‘Journal’ && parseInt(docId) === parseInt(journalId)) {
payment.setCurrentSublistValue({ sublistId: ‘apply’, fieldId: ‘apply’, value: true });
}
if (type === ‘Bill’ && parseInt(docId) === parseInt(billId)) {
payment.setCurrentSublistValue({ sublistId: ‘apply’, fieldId: ‘amount’, value: incomeTaxAmount });
}
payment.commitLine({ sublistId: ‘apply’ });
}
let paymentId = payment.save();
log.audit(‘Vendor Payment Created for Income Tax JE application only’, paymentId);
} catch (e) {
log.error(‘Failed to transform bill and apply JE’, e);
}
}