Creating Automatic Journal Entries Via BPM

Epicor BPM Custom Code Examples • For Epicor Kinetic, v10, v9

I covered this similar territory in my other article on Using Transaction Scopes In BPMs, but I figured there might be folks searching just for the example used within that article so here you go! Creating journal entries from BPMs is easy and fun! Ok, maybe not fun. You are going to need to reference this article to understand the details of adding assembly references to your DLL - we need to get GLJrnGrp and GLJournalEntry added in. After that, your code will just need to look like this - I’ve got annotations in here that are hopefully sufficient:

// Custom Code
///////////////////////////////////////////////////////////////////////////////
var jrnGrp = ServiceRenderer.GetService<Erp.Contracts.GLJrnGrpSvcContract>(Db);
var jrn = ServiceRenderer.GetService<Erp.Contracts.GLJournalEntrySvcContract>(Db);

Erp.Tablesets.GLJrnGrpTableset jrnGrpTs = new Erp.Tablesets.GLJrnGrpTableset();
Erp.Tablesets.GLJournalEntryTableset jrnTs = new Erp.Tablesets.GLJournalEntryTableset();

string groupId = "MYGROUP";

using (var txscope = IceDataContext.CreateDefaultTransactionScope())
{
  // Create the journal group
  jrnGrp.GetNewGLJrnGrp(ref jrnGrpTs);
  jrnGrpTs.GLJrnGrp[0].GroupID = groupId;
  jrnGrp.Update(ref jrnGrpTs);

  // Add a new journal to the group
  jrn.GetNewGlJrnHedTran(ref jrnTs, groupId);
  bool requiresUserInput;
  jrnTs.GLJrnHed[0].Description = "My Cool Journal Entry";
  jrn.PreUpdate(ref jrnTs, out requiresUserInput);
  jrn.Update(ref jrnTs);
  int journalNum = jrnTs.GLJrnHed[0].JournalNum;

  // Add the credit (GL account and amount hard coded for example)
  jrn.GetNewGLJrnDtlMnl(ref jrnTs, "MAIN", DateTime.Now.Year, "", "GJ", journalNum, 0);
  bool currCodeChanged;
  jrnTs.GLJrnDtlMnl[0].GLAccount = "12345|AA|123|0";
  jrn.ChangeGlAcct1(1, ref jrnTs, out currCodeChanged);
  jrnTs.GLJrnDtlMnl[0].TotCredit = (decimal)100.00;
  jrn.Update(ref jrnTs);

  // Add the debit
  jrn.GetNewGLJrnDtlMnl(ref jrnTs, "MAIN", DateTime.Now.Year, "", "GJ", journalNum, 0);
  jrnTs.GLJrnDtlMnl[1].GLAccount = "12345|BB|123|0";
  jrn.ChangeGlAcct1(2, ref jrnTs, out currCodeChanged);
  jrnTs.GLJrnDtlMnl[1].TotDebit = (decimal)100.00;
  jrn.Update(ref jrnTs);

  // Post it
  string notAllPosted;
  jrnGrp.CheckBeforePost(groupId);
  jrnGrp.PostGroupJournals(groupId, out notAllPosted);
  jrnGrp.UnlockGroup(groupId);
  
  Db.Validate();
  txscope.Complete();
}
///////////////////////////////////////////////////////////////////////////////