Auto Numbering - Customer ID

Gotcha.

Have a great weekend!

Mark W.

1 Like

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);

1 Like

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.

2 Likes

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.

1 Like

Will have to test that out. Thanks!!!

Chris,

I am testing this and see how well it works. When you are calling it, are you calling it within ToolClick for “New”?

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.

You can just call it on new.

What dll is Ice.Lib.NextValue in?

This would be in Ice.Lib.NextValue.dll. This is located in your server assemblies folder which will default open when adding a reference.

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.

Any thoughts on using the Erp.Internal.Lib.Shared.dll and the class Erp.Internal.Lib.CompanySequence.GetNextCompanySeq(company, sequencename)?

From the looks of it, it will create a record in the Erp.CompanySequence table if it’s missing and increment it. I just stumbled across it.

And it also looks like you can manually set it with SetCurrentCompanySequence( company, sequenceName, currentValue) method

Hi Tim,

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

CustomerAutoAssignError.docx (98.6 KB)

Thanks in advance,
Cyle

As you can see SetSequenceCurrentValue is expecting 3 parameters.

Change
NextValue.SetSequenceCurrentValue(NextSequenceCode, NextValueReset)

To
NextValue.SetSequenceCurrentValue(Db, NextSequenceCode, NextValueReset)

1 Like

Hi Jonathan,

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?

Thanks,
Cyle

I’m not sure how DMT works, but CustNum is autoincremented as far as I know so maybe just leave it.

Yes, just remove the C from the format.

It should not, as far as I know CustNum is the actual key used for references, the ID is only for display/input and can be changed after.

2 Likes

And same for Supplier IDs. If you want, you can go back and auto-number at anytime.

If you use Intercompany, the customer ID and Supplier ID for trading companies MUST be the company ID.

1 Like

Hey All,

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:

Vector = V0001, Sharmane = S0001, Vaas = V0002, Sound = S0002.

Has anyone accomplished something similar?

You’d need to have a different sequence for each letter.

So probably just do the same you are doing but whatever sequence code you are using should be dynamic based on the first letter.

Would it be easier to query the existing Vendor ID’s selecting the MAX VendID where the VendID starts with the first letter of the vendors name? Then just take the last 4 char, convert to an integeger and add 1 to it.