I use code lock when I need to assign a unique Number to a Notes document Field, e.g. A Purchase Order Number.
So if more than 1 processes are trying to get the next number in a sequence but you do not want then to get the same next number you lock the code so they run one after another therefore reducing the possibility of duplicate numbers.
Note, however, that this only works when the other processes competing to run that code are other threads in the same server process. In other words, it works well if you have no local replicas and it’s a Domino web application and is not clustered.
If you do have multiple replicas or you need to support Notes client use, then you need to do something more complicated.
If you have one server and you want to assign the number from a Notes workstation, you can use RunOnServer to cause the agent that assigns the number, to run on the server. Codelock should work in that case (though I haven’t tried it).
If you have multiple replicas, and people assigning numbers in all of them, you have a tough situation to prevent duplications. In that case you might either have a unique prefix for each replica, or else have a single shared number server — this can be done with a web service — but of course this does not support offline use.
Often, people make things difficult for themselves by insisting on a <i>sequential</i> number. The @Unique function creates an identifier that’s almost certain to be unique across all replicas, and it’s very, very easy to use.