Anyone have any ideas on the best way to get a new sequence from an Epicor function?
In a recent thread, Jose recommended to use code like this in a BPM to get a new sequence:
// Bring in Ice.Lib.NextValue.dll
const string sequenceName = "InvcGrpIDAA";
var nextVal = new Ice.Lib.NextValue(Db);
int nextGroupID = nextVal.GetNextSequence(sequenceName);
I added a reference to Ice.Lib.NextValue.dll but cannot figure out how to pass in Db context. If I give the library access to read data by pulling in a table reference to a random table, this.Db is available but it seems to be of a different type. I get the following error:
Argument 1: cannot convert from 'EFx.MyFunction.Implementation.ILibraryContext' to 'Ice.IceContext'
I’ll share the secret sauce. It’s not exactly a secret, just one of those things you need to be careful
with, as you could very easily do things that are not recommended.
ErpContext dbContext = new ErpContext();
// Bring in Ice.Lib.NextValue.dll
const string sequenceName = "InvcGrpIDAA";
var nextVal = new Ice.Lib.NextValue(dbContext);
int nextGroupID = nextVal.GetNextSequence(sequenceName);
//This is just the output of my function
output = nextGroupID.ToString();
Well, in the meantime, this is so easy, I’ll make a proper function and share it.
Thanks to @josecgomez for pointing it out and @timshuwy for showing us the way.