Merge field $aos_contracts_reference_code doesn't fill anything

If your id can be ugly, you can use the id field which is the GUID used in the database.

If you need more of a serial-number-presentable-to-a-customer, you might need to create an auto_increment field, there are several posts here in the Forums about that, for example:

I am the author of a paid add-on that greatly enhances template capabilities, it’s called PowerReplacer. That can also be used to facilitate automatic numbering and many other things.