Necro-answer!
Regardless, I couldn't find an answer to this particular issue, but I found one. I tried the different documentations and couldn't get passed the error you were getting.I felt it would be better to answer this one instead of creating a new thread.
I came across the following link:
https://www.docusign.com/supportdocs/dfs-admin-guide/Content/admin-guide/sample-js-code-custom-buttons.htm
It has a larger button example, and for whatever reason, this one was able to work properly once adjusted to work with my specific custom sObject, Project__c.
I've included my own code examples, which does have the code block from the above URL in it as well.
Attempt 1 - did not work after a lot of tweaking
{!REQUIRESCRIPT("/apex/dsfs__DocuSign_JavaScript?SourceID{!Project__c.Id}")}DocuSign_CreateEnvelope();
Attempt 2 - did not work after a lot of tweaking
var SourceID2 = window.sfdcPage.getEntityId();
window.location.href = "/apex/dsfs__DocuSign_CreateEnvelope?DSEID=0&SourceID="+SourceID2;
Debugging block to attempt to see if there was anything extra I needed from the source ID. There wasn't.
var SourceID1 = window.sfdcPage.entityId;
var SourceID2 = window.sfdcPage.getEntityId();
var SourceID3 = '{!Project__c.Id}';
var SourceID4 = DSGetPageIDFromHref();
console.log('This is the value of window.sfdcPage.entityId: '+SourceID1);
console.log('This is the value of window.sfdcPage.getEntityId(): '+SourceID2);
console.log('This is the value of !Project__c.Id: '+SourceID3);
console.log('This is the value of DSGetPageIDFromHref(): '+SourceID4);
This last block worked after changing the sObject at the very end to be the one I wanted. Besides that I didn't have to edit it at all. If you're looking to copy/paste a solution from this thread, it's this entire below piece you want.
//********* Option Declarations (Do not modify )*********//
var RC = '';var RSL='';var RSRO='';
var RROS='';var CCRM='';varCCTM='';
var CCNM='';var CRCL=''; var CRL='';
var OCO='';var DST='';var LA='';var CEM='';
var CES='';var STB='';var SSB='';var SES='';
var SEM='';var SRS='';var SCS ='';var RES='';
//*************************************************//
// Modify individual options here:
// Related Content (default no related content)
RC = ''; /*Ex: GetRelContentIDs("{!Opportunity.Id}");*/
// Recipient Signer Limit (default no limit)
RSL = ''; //Ex: '3'
// Recipient Starting Routing Order (default 1)
RSRO = ''; // Ex: '1'
// Recipient Routing Order Sequential (default not sequential)
RROS = ''; //Ex: '1'
// Custom Contact Role Map (default config role)
CCRM = ''; /*Ex: 'Decision Maker~Signer1;Economic Buyer~Carbon Copy'*/
// Custom Contact Type Map (default Signer)
CCTM = ''; /*Ex: 'Decision Maker~Signer;Economic Buyer~CC'*/
// Custom Contact Note Map (default no note)
CCNM = ''; /*Ex: 'Decision Maker~Note for DM;Economic Buyer~Note For EB;DEFAULT_NOTE~Default Note'*/
// Custom Related Contact List (default object contact)
CRCL = ''; /*Ex:'MyContacts__r,Email~Email__c;FirstName~First_Name__c;LastName~Last_Name__c;Role~Role__c,LoadDefaultContacts~0'*/
// Custom Recipient List
CRL = ''; /*Ex:'Email~;FirstName~;LastName~;Role~SignInPersonName~;RoutingOrder~;AccessCode~;RecipientNote~;SignNow~, LoadDefaultContacts~1'*/
// One Click Option (default edit envelope screen)
OCO = ''; //Ex: Tag
// DocuSign Template ID (default no template)
DST = ''; //Ex: '67870A79-A0B5-4596-8AC1-CC7CC1EA01EB'
// Load Attachments (default on)
LA = ''; //Ex: '0'
// Custom Email Message (default in config)
CEM = ''; //Ex: 'Envelope sent by [FirstName] [LastName] ([Email])!'
// Custom Email Subject (default in config)
CES = ''; //Ex: 'Re: Opportunity Name: {!Opportunity.Name}'
// Show Tag Button (default in config)
STB = ''; //Ex: '1'
// Show Send Button (default in config)
SSB = ''; //Ex: '1'
// Show Email Subject (default in config)
SES = ''; //Ex: '1'
// Show Email Message (default in config)
SEM = ''; //Ex: '1'
// Show Reminder/Expire (default in config)
SRS = ''; //Ex: '1'
// Show Chatter (default in config)
SCS = ''; //Ex: '1'
// Reminder and Expiration Settings
RES = ''; //Ex: '0,1,2,0,120,3'
//********* Page Callout (Do not modify) *********//
//This section is the one you change. Change the sObject reference to the one you want.
//Edit the reference to the sObject in the line below
window.location.href = "/apex/dsfs__DocuSign_CreateEnvelope?DSEID=0&SourceID={!sObject.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="+CES+"&SRS="+SRS+"&STB="+STB+"&SSB="+
SSB+"&SES="+SES+"&SEM="+SEM+"&SRS="+SRS+"&SCS="+SCS+"&RES="+RES;
Best Answer
From what I recall in making customizations to DocuSign for Salesforce (DSFS for short) for my company, you can't attach a document to the envelope using Javascript.
In my case, sending quotes out to customers via DocuSign, DocuSign automatically picks up anything (and everything) stored in an
Attachment
record where theParentId
field matches the Id of the record that you're initiating the envelope from (i.e. the 'SourceID' parameter that DSFS can accept).You could probably use Javascript to prompt for a file, and then proceed to save it as an
Attachment
in Salesforce...but it sounds like you're getting to the point where it makes more sense to develop a custom visualforce page (with a controller extension) to take care of this for you. The added benefit to that is that buttons that redirect users to a visualforce page are allowed with the Lightning Experience (whereas Javascript buttons are not).If you don't need any user interaction besides clicking the button (that is to say, the document you want to send already exists, or can be automatically generated), then your visualforce page can literally be one line
The
action
attribute specifies a method to be called (in either your controller, or an extension) after the constructor(s) are called, but before the page is rendered. If this method returns aPageReference
, the user is then immediately redirected to thatPageReference
(usually without seeing the blank Visualforce page that preceded it).If the method that you specify as the action inserts an
Attachment
, and you return aPageReference
to the entry point of DSFS (Page.dsfs__DocuSign_CreateEnvelope
), then that should accomplish what you're looking to do here.Also, because I think you may end up needing it, you may want to download a copy of the DocuSign for Salesforce Administrator's guide. Starting on page 62 (Custom Button Configuration) of that guide is an explanation of all of the parameters that you can pass to DSFS, and what they do.