Overview
The provided function, createJournalRecord, takes in request parameters, creates a journal entry, and applies this entry to a specified payment record if available.
Key Steps
- Extract Parameters from the Request
- Create a Journal Entry
- Apply the Journal Entry to a Payment Record
Extract Parameters from the Request
First, we extract the necessary parameters from the incoming request body.
let statementRecId = requestBody.statement_rec_id; let subsidiaryId = requestBody.subsidiary_id; let currencyId = requestBody.currency_id; let entityId = requestBody.entity_id; let paymentId = requestBody.payment_id; let totalAmountValue = requestBody.amount; let expenseAccountId = requestBody.expense_account_id; let charge = requestBody.charge; let apAccountsId = requestBody.ap_account_id; let departmentId = requestBody.department_id; let locationId = requestBody.location_id; let classId = requestBody.class_id; let toSubsidiaryId = requestBody.to_subsidiary_id; let projectCodeId = requestBody.project_code_id; let memo = unescape(requestBody.memo);
Create a Journal Entry
The journal entry is created using the extracted parameters. This step involves creating a new record of type “journalentry” and setting the necessary fields.
let journalId = this.createJournal(subsidiaryId, currencyId, memo, apAccountsId, expenseAccountId, charge, entityId, departmentId, locationId, classId, toSubsidiaryId, projectCodeId);
if (!nsUtility.checkForParameter(journalId)) {
return { status: "ERROR", reason: "ERROR_IN_CREATION_OF_Journal_ENTRY", data: "" };
}
Apply the Journal Entry to a Payment Record
If a payment ID is provided, the journal entry is applied to the corresponding payment record.
let paymentRecord = record.load({ type: "vendorpayment", id: paymentId, isDynamic: true });
let journalIndex = paymentRecord.findSublistLineWithValue({
fieldId: "internalid",
sublistId: "apply",
value: journalId
});
if (journalIndex !== -1) {
paymentRecord.selectLine({ sublistId: 'apply', line: journalIndex });
paymentRecord.setCurrentSublistValue({ sublistId: 'apply', fieldId: 'apply', value: true });
let transactionNumber = paymentRecord.getSublistValue({ sublistId: 'apply', fieldId: 'refnum', line: journalIndex });
paymentRecord.commitLine({ sublistId: 'apply' });
let unappliedAmount = paymentRecord.getValue("custbody_jj_amount_to_apply_gxin761");
unappliedAmount = parseFloat(unappliedAmount) - parseFloat(charge);
paymentRecord.setValue("custbody_jj_amount_to_apply_gxin761", unappliedAmount);
paymentRecord.save();
}
Return Status
After creating and potentially applying the journal entry, the function returns a status indicating success or failure.
return { status: "SUCCESS", reason: "JOURNAL_ENTRY_CREATED_AND_APPLIED_TO_BILL_PAYMENT", data: journalId };
Conclusion
This article outlined the process of creating a journal entry and applying it to a payment record in NetSuite. By following these steps, you can ensure efficient and accurate financial record management in your NetSuite environment.