Greetings Guys,
I am trying to find a way to generate an incident number after submission in the hooks file for records keeping purposes.
The incident number needs to be generated on submission due to the real possibility other users may be submitting records at the same time, it should pick the next available number in sequence.
The sequence can be simple with the first 2 digits being the current year ie: 14-00001 and then next one would be 14-00002, as records are inserted. The record number needs to be read only and MUST NOT update if the record is updated, so it should be after insert in my opinion.
Any ideas are appreciated,
Thanks
Auto Generate Incident Number
-
- AppGini Super Hero
- Posts: 85
- Joined: 2014-06-14 03:08
- Location: India
- Contact:
Re: Auto Generate Incident Number
Hi,
There are many ways to achieve this, The best way i recommend it to use after_insert function in hooks.
Get the selectedID after insert
and modify the Selected ID as per your requirement and run a update query.
I am just giving sample code. It may have some errors.
There are many ways to achieve this, The best way i recommend it to use after_insert function in hooks.
Get the selectedID after insert
and modify the Selected ID as per your requirement and run a update query.
I am just giving sample code. It may have some errors.
Code: Select all
$num_padded = sprintf("%05s", $data['Selectedid']); // to add 0's infront
$newId="14"+$num_padded ;
sql("update tablename set id=$newId where id={$data['Selectedid']} ",$eo);