Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

create sequental client number?


Reply


5 Posts   494 Views

Avatar
voodoochile

Community Member, 52 Posts

10 December 2011 at 8:07pm

Hi all
Currently i'm working on a project that has a client dataobject i have this setup and can add clients from both the CMS and also a front end form. as there is a current client list going in that has already established client numbering system, i would like new clients to have a number that follows on from the last number, this number needs to auto generate when a new client is added from either the CMS or the front end form.

so far i know this is done using onbeforewrite, but i have no idea of what to put or where to put it.
hope someone can help or atleast point me in the right direction thanks

Avatar
swaiba

Forum Moderator, 1799 Posts

10 December 2011 at 9:38pm

I'm guessing the "ID" is insufficient?

Avatar
voodoochile

Community Member, 52 Posts

11 December 2011 at 1:04pm

Hi Swaiba

The id maybe ok, i had considered using this and appending a group of numbers before, this would mean renumbering the entire client base that exists.
however as the project is aimed at consolidating several business functions currently residing in a series of excel spreadsheets and various other documents into a single application to be used company wide, this maybe a plausable solution as everything else is going to work around the client number.
the main reason for not wanting to use the id is more to learn an alternative method to solve this problem as it will no doubt come up later in the project when i start intergrating their mapping software and other systems their may be a requirement to have several fields that do this in a single table.

Avatar
voodoochile

Community Member, 52 Posts

14 December 2011 at 9:40pm

Hi

i have spoken to my client and they wish to keep thier current numbering system in place this makes Using the ID not possible

so if anyone could help please it would be appericated.

Avatar
swaiba

Forum Moderator, 1799 Posts

14 December 2011 at 10:06pm

$iNewCustomerNumber = intval(DB::query('SELECT MAX(CustomerNumber) FROM CustomerTable")->value())+1;