Custom Auto Number

Is there a way to have a customized auto number with customer prefix. I am currently making an inventory system and I have different Item types and subtypes for all my items. Let’s say I have an Item that belongs to the IT type i’d like to have a field that will have IT-00001 for the first item that belongs to this type. if it’s a furniture then it is FUR-00002, the number is auto increment but the prefix should change.Thanks

For example,

  1. Create an autoincrement field as ID of the table (so the newer item always has a larger ID),
  2. Use Row_Inserting event to get the last item of the type, e.g.

$LastID = ew_ExecuteScalar(“SELECT YourIDField FROM YourTable WHERE YourIDField LIKE '” . $rsnew[“Type”] . “-%’ ORDER BY YourAutoIncIDField DESC LIMIT 1”);If $rsnew[“Type”] is “IT”, then $LastID should contain the last ID of the type, say, “IT-00001”. Then you can split the ID by “-” using PHP’s explode() function to get the second part, increase by one to build your new ID, then set it to the field, e.g.$rsnew[“YourIDField”] = $YourNewID;

thank youi will try this

Hello,
Kindly help me here, i am trying to have a primary key in my table like TCB-DATE-NUMBER ie, TCB-210714-000001 … TCB-DATE-000002 …
I need with any example as i am new to php.Urgent help

Thank you

If you are new to PHP, you should learn the PHP basics from php.net website.After that, try to write a PHP global function in order to generate that custom auto number in Global Code of Server Events side in your PHPMaker project.You may then call that global function from Row_Inserting and assign it to your desired field.