99.9% of our BPM’s and processes in Epicor were written by my predecessors. I have made it may goal to evaluate 1 BPM (and form customizations) a week for improvement or remove it if it is no longer necessary. I am finding many that are broke, can be removed, or the code is painfully ugly.
In this case i am up to the BPM and sets the next customer Id. We already auto-number our customer ID’s. It is using Method 2 mentioned by Tim above. It seemed kind of quirky so i searched e10 for any updated method and found this thread. I want to give method 5 a try but not if there are issues already known with 10.2.
it seems that there was a change in the way that these processes need to be called somewhere along the way… seems that in the old version you didnt need to callout the database, but the newer you do… I believe that these are the two variations. try one and then the other.
nv.GetNextSequence(NextSequenceCode)
to
nv.GetNextSequence(this.Db,NextSequenceCode)
and
NextValue.SetSequenceCurrentValue(NextSequenceCode, NextValueReset);
To
NextValue.SetSequenceCurrentValue(this.Db,NextSequenceCode, NextValueReset);
by the way… i agree with @Mark_Wonsil on this… I typically do NOT promote auto sequencing of customer IDs EXCEPT in environments where there are many new customers per day… My experience says that humans who add a new customer can manually choose a good ID for a customer based on how they will remember the customer. The ID can be changed later if this is a probelm. Customer search allows for searching by name, ID or you can create a quicksearch to find them by address, phone number, contact, etc.
When you auto assign, you are basically guaranteeing that nobody will remember the ID (except for super high use customers) so the ID is just another number to try to remember.
Our finance group just wants a standard number for customer number, vendor number, ap groups, ar groups, payment groups, and so on. Anywhere it does not autonumber they wanted. One of our developers helped write a small set of code that reads a UD table with a key for the calling process and feeds back the number. The number is then incremented and stored back in the UD table. This method should work in the DMT tool as well because it is a BPM call.
I notice all of these solutions deal with Incrementing from the server. Here is a way to do it in the client using UserCodes:
using System.Linq;
//also use wizard to bring in UserCodesAdapter
long GetSeq(string WhichSeq, bool ReadOnly = false)
{
bool error = false;
long seq = 0;
var codeAdapter = new UserCodesAdapter(oTrans);
codeAdapter.BOConnect();
error = !codeAdapter.GetByID("AutoInc");
string errorMsg = string.Empty;;
if(!error)
{
var codes = codeAdapter.UserCodesData.UDCodes.AsEnumerable().Where(c => c.Field<string>("CodeID") == WhichSeq).FirstOrDefault();
if(codes == null)
{ //check for our inc code
error = true;
errorMsg = string.Format("Code {0} not found in AutoInc usercodes.",WhichSeq);
}
if(!error)
{
try
{
seq = (long)codes["Sequence_c"];
if(!ReadOnly) //we're gonna inc it
{
codes["Sequence_c"] = seq+1;
codes["RowMod"] = "U";
}
}
catch //return 0 and set to 1
{
if(!ReadOnly)
{
codes["Sequence_c"] = 1;
codes["RowMod"] = "U";
}
}
if(codes["RowMod"].ToString() == "U")
{
codeAdapter.Update();
}
}
}
codeAdapter.Dispose();
if(error) throw new Exception(errorMsg);
return seq;
}
To call it:
long seq;
seq = GetSeq("Elevator"); //by default it will inc after giving the seq#
MessageBox.Show("E "+seq.ToString());
seq = GetSeq("Elevator",true); //if you pass a true, it will NOT inc, but only supply the current value
MessageBox.Show("E2 "+seq.ToString());
seq = GetSeq("BROKE",true); //passing a non-exisitng code will provide an error
MessageBox.Show("B "+seq.ToString());
Setup:
Create a UserCodeType of “AutoInc” and add the desired sequences (in this case Elevator and GrainNum)
Using UD Field maintenance - add a longint field of Sequence_c to the UserCodes table.
In my case, I had it based off the change of another field. Also in my case, it was important that I get the seq without updating until customer saved the record, that way i wouldnt be incrementing if a record wasnt saved.
This is where I would have thought it was, but there is not a dll called this. Ah, it is in just the server assemblies and not client assemblies folder.
Working through the documentation, but i am getting an error message on the custom code. Not sure if the attachment will come through, but it is called Code: CS7036 "there is no argument given that corresponds to the required formal parameter ‘newValue’ of Next Value.SetSequenceCurrentValue(IceContext, strin, int)’
I am hoping to get the customer number to begin with 200000 and then auto tick up from there so that the next customer number is 200001
Thank you very much. It now works. Greatly appreciated.
When should I set the customer number? We are in the process of converting customers over and I plan on using DMT to populate the initial list.
I was also thinking about removing the “C” from the customer ID. I can simply remove the “C” from the following part of the code…correct? MyCust.CustID = string.Format(“C{0:000000}”"
I tested changing the customer ID to read only through the extended properties table after I created a few. There shouldn’t be any downstream impacts correct?
I’ve been working on automating our VendorID’s using the items you all have discussed here. I have it working the way it was intended to. I did make a minor change where instead of the C in front I grab the first letter of the name of the Vendor instead.
What I’m trying to accomplish now is how to get it to recognize when a letter is different from what was used previously. I would like it to behave like the following example: