function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
LIM AI KHOONLIM AI KHOON 

customized button to go to approval page

Hi guys,

I have created a button. When user click to the created button, I want it will redirect user to approval/reject page (as attachement). May I know how?
User-added image
LIM AI KHOONLIM AI KHOON
first you need to create a custom button field, choose onclick javascript as content source. Then you can paste this code. Change according to your requirement.

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")}

var result = sforce.connection.query("SELECT Id FROM ProcessInstanceWorkitem WHERE processInstance.TargetObjectId='{!objectName__c.Id}'");

var approvals = result.getArray("records");

if(approvals != undefined && approvals.length > 0) {
var approvalID = approvals[0].Id;
window.open('/p/process/ProcessInstanceWorkitemWizardStageManager?id='+approvalID);
}
else {
alert("There are no approvals pending.")
}