1

The code below was created for us as a custom button in the UI on the Opportunity object. I would like to now include it in a Visualforce page for a custom object as a Commandbutton. I am not very familiar with JavaScript. Can anyone help me convert this code to a script I can use in a VF page? Thanks.

{!REQUIRESCRIPT("/apex/dsfs__DocuSign_JavaScript")} 
//********* Option Declarations (Do not modify )*********// 
var CRL=''; 
var DST=''; 
var CES='';
//*************************************************// 
// Modify individual options here: 
// Related Content (default no related content) 
// Custom Recipient List 
CRL = 'Email~{!JSENCODE(Opportunity.Primary_Contact_Email__c)};
FirstName~{!JSENCODE(Opportunity.Primary_Contact_FirstName__c)};
LastName~{!JSENCODE(Opportunity.Primary_Contact_LastName__c)};
Role~Signer1,Email~test@test.com;FirstName~Test;LastName~Test1;
Role~Signer 2'; 
DST = '0E9AB63C-62C0-4D01-B91A-E58849B7B573'; 
CES='Insertion Order signature request for {!JSENCODE(Opportunity.Account_Name_Rendered__c)}';
//********* Page Callout (Do not modify) *********// 
window.location.href = "/apex/dsfs__DocuSign_CreateEnvelope?DSEID=0&STB=1&SourceID={!Opportunity.Id}&LA=0&CRL="+CRL+"&DST="+DST+"&CES="+CES; 
//*******************************************//
2
  • just use <script> tags?
    – Novarg
    Dec 1, 2015 at 14:58
  • Thanks @Novarg, but where do I need to put them and do I need to remove the {!REQUIRESCRIPT...} reference?
    – J. Neilan
    Dec 1, 2015 at 15:14

1 Answer 1

1

Here it is. Create a vf page with below code save the page with executeScript name

<apex:page standardController="opportunity">
    <apex:form>
    <apex:includeScript value="{!$Resource.example_js}"/>
     <script>
     function executeScript()
     {

      var CRL=''; 
        var DST=''; 
        var CES='';

        CRL = 'Email~{!JSENCODE(Opportunity.Primary_Contact_Email__c)};
        FirstName~{!JSENCODE(Opportunity.Primary_Contact_FirstName__c)};
        LastName~{!JSENCODE(Opportunity.Primary_Contact_LastName__c)};
        Role~Signer1,Email~test@test.com;FirstName~Test;LastName~Test1;
        Role~Signer 2'; 
        DST = '0E9AB63C-62C0-4D01-B91A-E58849B7B573'; 
        CES='Insertion Order signature request for {!JSENCODE(Opportunity.Account_Name_Rendered__c)}';
        //********* Page Callout (Do not modify) *********// 
        window.location.href = "/apex/dsfs__DocuSign_CreateEnvelope?DSEID=0&STB=1&SourceID={!Opportunity.Id}&LA=0&CRL="+CRL+"&DST="+DST+"&CES="+CES;
        }
     </script>
     <input type="button" value="Execute script" onclick="executeScript();"/> 
    </apex:form>
</apex:page>

New code

<apex:page standardController="opportunity">
        <apex:form>
         <script>
         function executeScript()
         {

          var CRL=''; 
            var DST=''; 
            var CES='';

            CRL = 'Email~{!JSENCODE(Opportunity.Primary_Contact_Email__c)}';             
            DST = '0E9AB63C-62C0-4D01-B91A-E58849B7B573'; 
            CES='Insertion Order signature request for {!JSENCODE(Opportunity.Account_Name_Rendered__c)}';
            window.location.href = "/apex/dsfs__DocuSign_CreateEnvelope?DSEID=0&STB=1&SourceID={!Opportunity.Id}&LA=0&CRL="+CRL+"&DST="+DST+"&CES="+CES;
            }
         </script>
         <input type="button" value="Execute script" onclick="executeScript();"/> 
        </apex:form>
    </apex:page>

Now open page executeScript and pass opportunity id like below example

/apex/executeScript?Id=0061d55rf5th54g

13
  • Thanks. I tried that but got an error that the $Resource.example_js was not found.
    – J. Neilan
    Dec 1, 2015 at 17:09
  • 1
    just remove <apex:includeScript value="{!$Resource.example_js}"/> this
    – Ratan Paul
    Dec 1, 2015 at 17:10
  • Thanks. I removed that and everything saves. However, when I press the Commandbutton, all it does is refresh the page. Do you know how I can debug the button to figure out why it's not invoking the script?
    – J. Neilan
    Dec 1, 2015 at 17:15
  • Thanks. It says "Uncaught SyntaxError: Unexpected string" but doesn't give any more info than that. Any ideas?
    – J. Neilan
    Dec 1, 2015 at 17:24
  • Do you know why it might be happening? Is my window.location.href component formatted properly? I did try hard coding the URL and it does work. For some reason, it's not reading it properly in my script. Thanks for your help!
    – J. Neilan
    Dec 1, 2015 at 17:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .