9-Using Epicor Transaction Scopes in BPMs - GingerHelp
9-Using Epicor Transaction Scopes in BPMs - GingerHelp
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
// Custom Code
//////////////////////////////////////////////////////////
var jrnGrp = ServiceRenderer.GetService<Erp.Contracts.GLJr
var jrn = ServiceRenderer.GetService<Erp.Contracts.GLJourn
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 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);
// 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:
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):
...
// Post it
jrnGrp.UnlockGroup(groupId);
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!
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
PREVIOUS
NEXT
LET’S CHAT!
CONTACT US
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
GingerHelp is an
independent consulting
practice with no direct
© 2019 - 2023 GingerHelp,
affiliation with Epicor® or
LLC
Infor®.
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