Page 1 of 1

Auto Generate Incident Number

Posted: 2014-10-06 13:13
by nmartin1182
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

Re: Auto Generate Incident Number

Posted: 2014-10-07 04:07
by udayvatturi
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.

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