Full Use Case:
Is there a way to keep a user from merging/emailing a document unless a validation rule is passed? Or a certain field has a certain value? How do I control when a user can generate a document?
We suggest to do one of the following:
1. Create a formula field on the object and in that formula field you can have an IF statement that checks for field criteria or even current user criteria and then if passes your needs then displays a link or even an image button that would then provide a link they can click which is the same link you put in the button code that you click to generate the document. If the criteria is not met then what we found cool is you can also provide text of what is wrong with the record in order to be able to generate the document to provide some guidance. Or can display anything you want. This makes the “button” to generate a document only available when the record is ready and can control it this way.
2. Create document generation by automation using process builder based on some field value changing. You can setup a checkbox for a picklist for example to set a value that would initiate the document generation to happen in the back end. As part of the document action also you could update that field value to unchecked or a picklist value like “Generated” after the document action has finished. The point here is that now you can put permissions and validation rules around changing this field that initiates the document action.