Drawloop Button: Lock ‘Generate Document’ button until approval is given via an approval process

Problem:

You would like Users to generate a document ONLY after the record has gone through an approval process.

Solution:

After configuring the Salesforce approval process, create a custom button using the sample syntax below:

{!REQUIRESCRIPT("/soap/ajax/26.0/connection.js")} 
var test = sforce.connection.query("SELECT Id From ProcessInstance WHERE TargetObjectId ='{!Opportunity.Id}' AND Status = 'Pending' Limit 1");

if (test.size == 0) 
window.location.href = '/apex/loop__looplus?sessionId={!$Api.Session_ID}&eid={!Opportunity.Id}';

else 
alert('Cannot Run DDP while record is LOCKED');

Scroll to top