Add a custom body field on the invoice group PDF.
One field is for subsidiary details and the other for bank metrix details.
And make these fields as hidden.
Upload a user event script with an entry point beforeLoad().
const beforeLoad = (scriptContext) => {
try {
let newRecord = scriptContext.newRecord;
let subsidiary = newRecord.getValue("subsidiary");
if (subsidiary) {
let subsidiaryRecord = record.load({
type: record.Type.SUBSIDIARY,
id: subsidiary,
});
// Retrieve specific fields from the subsidiary record
let subsidiaryName = subsidiaryRecord.getValue({ fieldId: 'name' });
let registeredAddress = subsidiaryRecord.getValue({ fieldId: 'custrecord_mf_registered_address' });
let companyRegNumber = subsidiaryRecord.getValue({ fieldId: 'custrecord_alf_company_reg_num' });
let vatRegistrationNumber = subsidiaryRecord.getValue({ fieldId: 'federalidnumber' });
let concatenatedValues = subsidiaryName + '\n\n' + registeredAddress + '\n\n' + companyRegNumber + '\n\n' + vatRegistrationNumber + '\n\n';
newRecord.setText({ fieldId: 'custrecord_cc_subsidiary_details', text: concatenatedValues })
newRecord.setText({ fieldId: 'custrecord_cc_subsidiary_address', text:subsidiaryRecord.getText("mainaddress_text") })
} else {
log.debug("No subsidiary ID found on the new record");
}
bankMetrix(newRecord)
} catch (e) { log.error("error@beforeload", e) }
}
return { beforeLoad }
});
function bankMetrix(newRecord) {
try {
let invoicegroupSearchObj = search.create({
type: "invoicegroup",
filters: [
["internalid", "anyof", newRecord.id]
],
columns: [
search.createColumn({
name: "custbody_mf_bank_name",
join: "transaction",
label: "Bank Name"
}),
search.createColumn({
name: "custbody_alf_subsidiary_name",
join: "transaction",
label: "Subsidiary Name"
}),
search.createColumn({
name: "custbody_mf_bank_acct_number",
join: "transaction",
label: "Bank Account Number"
}),
search.createColumn({
name: "custbody_mf_bank_sort_code",
join: "transaction",
label: "Bank Sort Code"
}),
search.createColumn({
name: "custbody_mf_bank_iban",
join: "transaction",
label: "IBAN"
}),
search.createColumn({
name: "custbody_mf_bank_bic",
join: "transaction",
label: "BIC"
})
]
});
let searchResultCount = invoicegroupSearchObj.runPaged().count;
if (searchResultCount > 0) {
invoicegroupSearchObj.run().each(function (result) {
let bankName = result.getValue({
name: "custbody_mf_bank_name",
join: "transaction"
});
let subsidiaryName = result.getValue({
name: "custbody_alf_subsidiary_name",
join: "transaction"
});
let bankAccountNumber = result.getValue({
name: "custbody_mf_bank_acct_number",
join: "transaction"
});
let bankSortCode = result.getValue({
name: "custbody_mf_bank_sort_code",
join: "transaction"
});
let iban = result.getValue({
name: "custbody_mf_bank_iban",
join: "transaction"
});
let bic = result.getValue({
name: "custbody_mf_bank_bic",
join: "transaction"
});
let concatenatedBankValues =
(checkForParameter(bankName) ? "Bank Name: " + bankName + '\n\n' : '') +
(checkForParameter(subsidiaryName) ? "Account Name: " + subsidiaryName + '\n\n' : '') +
(checkForParameter(bankAccountNumber) ? "Account No: " + bankAccountNumber + '\n\n' : '') +
(checkForParameter(bankSortCode) ? "Sort Code: " + bankSortCode + '\n\n' : '') +
(checkForParameter(iban) ? "IBAN: " + iban + '\n\n' : '') +
(checkForParameter(bic) ? "SWIFT/BIC: " + bic + '\n\n' : '');
newRecord.setText({ fieldId: 'custrecord_cc_bankmetrix_details', text: concatenatedBankValues })
});
}
} catch (e) { log.error("error@bankMetrix", e) }
}