Function to add GL Lines in a custom transaction

/**
 * Function defined to create custom transaction record with GL Lines
 * @param {Number} debitAmount 
 * @param {Number} customerId
 * @returns {Number}
 */
function createReclassificationJournal(debitAmount, customerId) {
 try {
   let tranRecObj = record.create({ type: 'customtransaction_jj_revenue_reclassify', isDynamic: true });
   tranRecObj.selectNewLine({ sublistId: 'line' });
   tranRecObj.setCurrentSublistValue({ sublistId: 'line', fieldId: 'account', value: DEFFERED_ACCOUNT });
   tranRecObj.setCurrentSublistValue({ sublistId: 'line', fieldId: 'debit', value: debitAmount });
   tranRecObj.setCurrentSublistValue({ sublistId: 'line', fieldId: 'entity', value: customerId });
   tranRecObj.setCurrentSublistValue({ sublistId: 'line', fieldId: 'memo', value: "Reversed the GL from Deferred revenue" });
   tranRecObj.commitLine({ sublistId: 'line' });
   tranRecObj.selectNewLine({ sublistId: 'line' });
   tranRecObj.setCurrentSublistValue({ sublistId: 'line', fieldId: 'account', value: SALES_ACCOUNT });
   tranRecObj.setCurrentSublistValue({ sublistId: 'line', fieldId: 'credit', value: debitAmount });
   tranRecObj.setCurrentSublistValue({ sublistId: 'line', fieldId: 'entity', value: customerId });
   tranRecObj.setCurrentSublistValue({ sublistId: 'line', fieldId: 'memo', value: "Posted back to the Sales account" });
   tranRecObj.commitLine({ sublistId: 'line' });
   let constomTranId = tranRecObj.save();
   return constomTranId;
 } 
catch (e) {
   log.error('error@createReclassificationJournal', e);
   return false;
 }
}

Leave a comment

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