I created a section for appointment record (channel type). Each appointment record has different fields, i.e. customer name, phone#, address, etc... I would like to set a unique appointment_record_id (Numeric, i.e. 234) for each record. Is there any way to create it?
If you were to do this on entry save, it'd be much easier/cleaner.
The plugin would check the
isNewEntry param to make this this is a new entry and not an existing one.
If it's new, you could generate a random numeric value with mt_rand, assign it to your custom field and left the request continue so Craft can save it to the entry.
A string field for the unique identifier would be better though, since mt_rand will not always produce unique numbers (for unique numbers you'd need to keep a separate database table and obtain id's within a transaction). If you'd use strings you could use uniqid('', true) if you deploy on a single server, or better use a uuid/guid.