You shouldn't need these to get a serial number assigned to a new record. Using them in a script risks generating records with duplicate values if you have two or more users doing this at the same time.
If you have defined a field to auto-enter a serial number, simply creating (or comitting if you specify that option) a new record will enter a serial number into the field of the new record--no use of these functions nor any scripting needed.
Didn't work first, got a message about missing value in the id field but now it works.
When you add a field with an auto-entered serial number, existing records will not automatically get the serial number. You'd have to update them before they'd have a serial number. Replace field contents in the Records Menu has an option for entering serial numbers and updating entry options that serves well for such an update of existing records.