Auto Numbering - Customer ID

(Mark Wonsil) #21


Have a great weekend!

Mark W.

(Tim Shoemaker) #22

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.


NextValue.SetSequenceCurrentValue(NextSequenceCode, NextValueReset);
NextValue.SetSequenceCurrentValue(this.Db,NextSequenceCode, NextValueReset);

(Tim Shoemaker) #23

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.

(Josh Owings) #24

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.

(Chris Conn) #25

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);
	error = !codeAdapter.GetByID("AutoInc");
	string errorMsg = string.Empty;;
	   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);	
			  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
				  codes["Sequence_c"] = 1;
				  codes["RowMod"] = "U";	

			if(codes["RowMod"].ToString() == "U")
	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());

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.

(Chai Chang) #26

Will have to test that out. Thanks!!!

(Chai Chang) #27


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

(Chris Conn) #28

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.

(Theodore Koch) #29

What dll is Ice.Lib.NextValue in?

(Dan Edwards) #30

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

(Theodore Koch) #31

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.