0% found this document useful (0 votes)
50 views7 pages

9-Using Epicor Transaction Scopes in BPMs - GingerHelp

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views7 pages

9-Using Epicor Transaction Scopes in BPMs - GingerHelp

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

5/16/24, 3:46 PM Using Epicor Transaction Scopes in BPMs — GingerHelp

[email protected]

USING EPICOR
T R A N SAC T I O N S C O P E S I N
BPMS
ADAM ELLIS · JULY 9, 2020

EPICOR ERP - KINETIC, V10, & V9

I was recently tasked by one of my customers to create a BPM that, upon


shipping a transfer order, would automatically create a GL journal entry
that moved the cost of their internal freight from the sending location to
the destination. And while that may sound daunting, if you follow the
steps here to understand how to use business objects within a BPM it
ends up just being some code that looks like this:

// Custom Code
//////////////////////////////////////////////////////////
var jrnGrp = ServiceRenderer.GetService<Erp.Contracts.GLJr
var jrn = ServiceRenderer.GetService<Erp.Contracts.GLJourn

Erp.Tablesets.GLJrnGrpTableset jrnGrpTs = new Erp.Tableset


Erp.Tablesets.GLJournalEntryTableset jrnTs = new Erp.Table

string groupId = "MYGROUP";

// Create the journal group


jrnGrp.GetNewGLJrnGrp(ref jrnGrpTs);

https://www.gingerhelp.com/knowledgebase-epicor-erp/using-transaction-scopes-in-bpms 1/7
5/16/24, 3:46 PM Using Epicor Transaction Scopes in BPMs — GingerHelp

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 ex
jrn.GetNewGLJrnDtlMnl(ref jrnTs, "MAIN", DateTime.Now.Year
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
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);
//////////////////////////////////////////////////////////

https://www.gingerhelp.com/knowledgebase-epicor-erp/using-transaction-scopes-in-bpms 2/7
5/16/24, 3:46 PM Using Epicor Transaction Scopes in BPMs — GingerHelp

But when I had a variation of this code in place I got this error:

The underlying provider failed on EnlistTransaction.

Clear as mud, right? You can read up on this online and get even more
confused if you like, but in short Epicor is telling us to wrap our call in a
transaction. This is the same sort of idea you would find in the SQL world
where you put your logic into a transaction block and if anything fails it
rolls everything back. With something like a journal entry, it makes
complete sense that you might have a lot of cascading logic occurring
and this unclear error is actually making a very clear and sensible
suggestion to you. Transactions are pretty easy within BPMs - all you’ve
got to do is wrap your code inside of a using statement where you
validate and complete the transaction within (I chopped down the code
from above just so you can see contextually where the new lines go):

// Put this using line in where transactions really start


using (var txscope = IceDataContext.CreateDefaultTransacti
{
// Create the journal group
jrnGrp.GetNewGLJrnGrp(ref jrnGrpTs);

...

// Post it
jrnGrp.UnlockGroup(groupId);

// Use Db.Validate() to make sure the transaction is all


Db.Validate();

// Complete the transaction

https://www.gingerhelp.com/knowledgebase-epicor-erp/using-transaction-scopes-in-bpms 3/7
5/16/24, 3:46 PM Using Epicor Transaction Scopes in BPMs — GingerHelp

txscope.Complete();
}

And that’s it, my problem went away and I was able to see those nice
journal entries automatically being written. Hope this helps!

LET'S CHAT ABOUT YOUR EPICOR ERP


CUSTOMIZATION PROJECT

AUTHOR: Adam Ellis


Adam Ellis is the owner of
GingerHelp. Adam is a lifelong
entrepreneur and has extensive ERP
and mobile software knowledge
through his consulting and
management experience. He has a
passion for exploring innovative ideas
and how they can change the status
quo. Connect with Adam on LinkedIn
to learn more about his involvement
in the ERP space.

FACEBOOK TWI TTER PINTEREST 0 LIKES

COMMENTS (0) Newest First

https://www.gingerhelp.com/knowledgebase-epicor-erp/using-transaction-scopes-in-bpms 4/7
5/16/24, 3:46 PM Using Epicor Transaction Scopes in BPMs — GingerHelp

Preview POST COMMENT…

PREVIOUS

CREATING AUTOMATIC JOURNAL ENTRIES VIA BPM


EPICOR BPM, EPICOR ERP

NEXT

ADDING CUSTOM TABLES TO A SCREEN IN EPICOR


EPICOR BAQ, EPICOR CUSTOMIZATION, EPICOR ERP

LET’S CHAT!

CONTACT US

GINGERHELP, SERVIC PRODU KNOWLEDGE


LLC ES CTS BASE

8685 Fox Epicor ERP Epicor ERP Epicor ERP Articles


Lake Road Consulting Extensions Infor VISUAL Articles
P21 ERP Infor Dynamics 365

https://www.gingerhelp.com/knowledgebase-epicor-erp/using-transaction-scopes-in-bpms 5/7
5/16/24, 3:46 PM Using Epicor Transaction Scopes in BPMs — GingerHelp

Sterling, OH Consulting VISUAL ERP Articles


44276 USA Infor Extensions Crystal Reports
VISUAL ERP Articles
 Consulting SSRS Articles
[email protected] Dynamics Bezlio for Mobile
365 ERP Articles
Consulting
SSRS
Developer
Services
Crystal
Reports
Consulting

GingerHelp is an
independent consulting
practice with no direct
© 2019 - 2023 GingerHelp,
affiliation with Epicor® or
LLC
Infor®.

Terms & Conditions |


Epicor®, Vantage®, and Privacy Policy
Prophet 21™ are registered
trademarks of Epicor
Software Corporation®.
Infor® and VIUSAL® are
registered trademarks of
Infor®.
Crystal Reports® is a
registered trademark of SAP
AG.

https://www.gingerhelp.com/knowledgebase-epicor-erp/using-transaction-scopes-in-bpms 6/7
5/16/24, 3:46 PM Using Epicor Transaction Scopes in BPMs — GingerHelp

https://www.gingerhelp.com/knowledgebase-epicor-erp/using-transaction-scopes-in-bpms 7/7

You might also like