Trick to set workflow for Opportunities converted from Lead

By | June 10, 2013

A Lead can be converted to an Opportunity by “Convert to Opportunity” button available on the lead summary screen.  We can also add the same in workflow using Create opportunity workflow action; however when we convert a lead to an opportunity workflow is not set. Surprisingly Opportunity table level script also is not fired when we are generating the same from the Lead.

We had to apply a trick to nullify this behavior and enable Opportunity workflow. As you know that if Workflow is enabled and workflow id is not generated for any entity we see the “Accept” button to enable the workflow.

Clicking Accept button enables the workflow for the opportunity however we needed to put it directly into the workflow cycle rather than going through the Accept button.
 Below is the script that we had written for clicking on the Accept button automatically and progress the workflow to next stage.
 //Function to Progress lead and opportunity workflow
function OpportunityWorkflow()
{
//’if accept button is visible the click it
var WfButtons = getElementsByClassName(“WFBUTTON”);
if(WfButtons)
{
for(i=0;i<=WfButtons.length-1;i++)
{
var aButton = new String(WfButtons[i].innerText);
if(aButton.toLowerCase()==”accept”)
{
WfButtons[i].click();
}
}
}
}
 
//’Find document elements using class name
function getElementsByClassName(sClass)
{
var retnode = [];
var elem = document.getElementsByTagName(‘*’);
for (var i = 0; i < elem.length; i++)
{
var classes = elem[i].className;
if (sClass == classes)
retnode.push(elem[i]);
}
return retnode;
}