Problem:
You only want Users to be able to generate a document when an attachment with a specific name exists for that record. Also, the attachment should be included in the generate document package.
Solution:
After configuring the Salesforce approval process, create a custom button using the sample syntax below:
{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
var documentIds = new Array();
var documents = sforce.connection.query("SELECT Id FROM Attachment WHERE ParentId = '{!Contact.Id}' AND Name LIKE '%Invoice%'");
if (documents && documents.size > 0) {
for (var i = 0; i < documents.size; i++)
documentIds.push(documents.records[i] ? documents.records[i].Id: documents.records.Id);
window.location.href=
'/apex/loop__looplus?eid={!Contact.Id}&sessionId={!$Api.Session_ID}&attachIds='+documentIds.join(',');
}
else
alert('Please add a document to this Contact.');