1) What kind of data should be used for the reception number? (Campaign ID + UserID or something?)
I would appreciate it if you could tell me the best method.
There's no one "best" answer to that question.
Is Campaign ID + Marketo Person ID (not "user" ID) a unique enough identifier for your business?
A given lead doesn't necessarily have the same ID over time, due to merges. So you might end up with value "1234-56789" on a person whose ID is currently 56790 (having been merged w/56789 at some point). But that also means 56789 is gone from the system and, within reason, will not be reused. So it's probably acceptable for this specific, non-cryptographic use case.
However, you can't use the {{campaign.id}} token from JS unless you're on a Marketo LP. So this isn't very scalable. Since browsers are good at creating random numbers, you might as well gen it on the fly:
{
const formReceiptNumber = new Date().getTime() + "-" + crypto.getRandomValues(new Uint32Array(1))[0].toString()
MktoForms2.whenReady(function(mktoForm){
mktoForm.addHiddenFields({
formReceiptNumber: formReceiptNumber
});
});
}
2) I would like to store the receipt number without overwriting it, but I am concerned that it will be overwritten if I use a custom field.
This is not a concern. In Field Management, block updates from form fillouts. Note this isn't any different with standard vs. custom fields.