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
Kathryn BullockKathryn Bullock 

Changing Javascript to Lightning


I am trying to convert a javascript button to a lightning controller.  I have the basis of the controller, but how do I add the 'if this oppty type, then select this document' and the 'require these parts' sections in the lightning controller?

//********* Option Declarations (Do not modify )*********// 

var RC = '';var RSL='';var RSRO='';var RROS='';var CCRM='';var CCTM='';var CCNM='';var CRCL=''; var CRL='';var OCO='';var DST='';var LA='1';var CEM='';var CES='';var STB='';var SSB='';var SES='';var SEM='';var SRS='';var SCS ='';var RES=''; 

//********* Page Callout (Do not modify) *********// 
if("{!Opportunity.Authorized_Signer__c}" == false) 

alert('Must select an Authorized Signer to send to'); 


//KIA 4-6-18 Must have Authorized Signer Email Address 
if("{!Opportunity.Authorized_Email__c}" == false) 

alert('Oops! You are trying to send to a contact with no email address. Go to the Contact Record, add an email address and then resend the DocuSign.'); 


//KSJ 3-1-17 Must have agreement terms// 

if("{!Opportunity.Agreement_Term__c}" == ''|| "{!Opportunity.Agreement_Term__c}" == null ) 

alert('Agreement Term cannot be blank'); 


//KSJ 3-1-17 Must have auto renewal terms// 

if("{!Opportunity.Auto_Renewal_Term__c}" == ''|| "{! Opportunity.Auto_Renewal_Term__c}" == null) 

alert('Auto Renewal Term must be filled in'); 


//KSJ 3-1-17 Container type cannot be blank// 

if("{! Opportunity.Oppty_Type__c }" == "UCO Service" && {!(ISBLANK( Opportunity.Outdoor_Container_Type__c ))}) 

alert('Must have an Outdoor Container Type' ); 


//KSJ 3-1-17 For Trap must have #of trap agreement// 

if("{! Opportunity.Oppty_Type__c }" == "Trap Service" && {!(ISBLANK( Opportunity.No_traps_agreement__c ))}) 

alert('# Traps - Agreement cannot be blank' ); 


//KSJ 3-1-17 Indoor container cannot be blank// 

if("{! Opportunity.Oppty_Type__c }" == "UCO Service & Indoor Equipment" && "{! Opportunity.Indoor_Container_Type__c}" == '' || "{!Opportunity.Indoor_Container_Type__c}" == null ) 

alert('# Indoor Container Type cannot be Blank' ); 


//KSJ 3-1-17 Must have a quote number// 

if("{! Opportunity.Oppty_Type__c }" == "UCO Service & Indoor Equipment" && {!(ISBLANK( Opportunity.Quote_No__c ))}) 

alert('Quote No cannot be blank' ); 


CES='Documents for your Review and Signature'; 

//4-17-17 RAM commented out Alert CRL 
// Custom Recipient List (Individual) 
CRL='Email~{!Opportunity.Authorized_Email__c};LastName~{!Opportunity.Authorized_Signer__c};Role~Authorized Signer;RoutingOrder~1,Email~{!Opportunity.OwnerEmail};FirstName~{!Opportunity.OwnerFirstName};LastName~{!Opportunity.OwnerLastName};Role~Opportunity Owner;RoutingOrder~2,Email~{!Opportunity.Office_Mgr_Email__c};LastName~{!URLENCODE(JSENCODE(Opportunity.Facility__c))};Role~Carbon Copy;RoutingOrder~3'; 

// Custom Contact Role Map (default config role) 
CCRM = 'Authorized Signer~Authorized Signer;Opportunity Owner~Opportunity Owner;Carbon Copy~Carbon Copy'; 

// Custom Contact Type Map (default Signer) 
CCTM = 'Authorized Signer~Signer;Opportunity Owner~Signer;Carbon Copy~Carbon Copy'; 


//********* Page Callout (Do not modify) *********// 

window.location.href = 
"/apex/dsfs__DocuSign_CreateEnvelope?DSEID=0&SourceID={!Opportunity.Id}&RC="+RC+"&RSL="+RSL+"&RSRO="+RSRO+"&RROS="+RROS+"&CCRM="+CCRM+"&CCTM="+CCTM+"&CRCL="+CRCL+"&CRL="+CRL+"&OCO="+OCO+"&DST="+DST+"&CCNM="+CCNM+"&LA="+LA+"&CEM="+CEM+"&CES= "+RES; 


global class DocusignRedirect {
	private static final STRING PARAM_DSEID = 'DSEID';
    private static final STRING PARAM_SOURCE_ID = 'SourceID';
    private static final STRING PARAM_SOURCE_CRL = 'CRL';
    private Opportunity anOpportunity = null;
    public DocusignRedirect(ApexPages.StandardController stdController)
        Id opportunityId = stdController.getRecord().Id;
        this.anOpportunity = DAL_Opportunity.getById(opportunityId);
    public PageReference autoRun()
        if (this.anOpportunity == null)
            return null;
        PageReference pageRef = Page.dsfs__Docusign_CreateEnvelope;
        pageRef.getParameters().put(PARAM_DSEID, '0');
        pageRef.getParameters().put(PARAM_SOURCE_ID, this.anOpportunity.Id);
        pageRef.getParameters().put(PARAM_CRL, this.getCRL());
        return pageRef;
    private String getCRL()
        return 'Email~' + anOpportunity.Authorized_Email__c +
            ';Name~' + anOpportunity.Authorized_Signer__c +

Rajasree JayarajRajasree Jayaraj

Hi Kathryn,
You need to declare this variable: 

private static final STRING PARAM_DST='DST';

Use this variable in your page ref parameters to pass:

pageRef.getParameters().put(PARAM_DST,'paste the docusign template ID');


Hope this helps!