How to implement Signer Attachment in Docusign? - c#

The requirement which I have regarding docusign is I need to implement Signer Attachment and that same scenario is mentioned at [https://github.com/docusign/docusign-soap-sdk/wiki/Code-Walkthrough-_-Signer-Attachments]
But I am not sure how do I achieve with code in C#. As not sure how do I attach it to Envelope?
I want to send someone a contract letter to sign and also request them attach few docs and when all of that is completed , those docs should be sent to my email.
Anyone knows if I can achieve it with docusign?

The previous entry is not bad... I got it working eventually. But this code below is solid, in production, and works great! It also uses anchor strings.
EnvelopeDefinition env = new EnvelopeDefinition();
env.EmailSubject = "Please sign this document set";
Document doc4 = new Document
{
DocumentBase64 = doc4PdfBytes,
Name = "Voided Check Attachment", // can be different from actual file name
FileExtension = "pdf",
DocumentId = "4"
};
env.Documents = new List<Document> { doc4 };
SignerAttachment signAttachDoc = new SignerAttachment
{
TabLabel = "Attach your voided check",
DocumentId = "1",
TabId = "1",
PageNumber = "1",
AnchorString = "/at1/",
AnchorUnits = "pixels",
AnchorXOffset = "0",
AnchorYOffset = "0",
AnchorIgnoreIfNotPresent = "false",
};
Tabs signer1Tabs = new Tabs
{
SignerAttachmentTabs = new List<SignerAttachment> { signAttachDoc }
};
signer1.Tabs = signer1Tabs;
Recipients recipients1 = new Recipients
{
Signers = new List<Signer> { signer1 }
};
env.Recipients = recipients1;

Here is how we can do it while using C# SDK
create a signer object
Signer signer = new Signer();
signer.Name = recipientName;
signer.Email = recipientEmail;
signer.RecipientId = "1";
then create attachment tabs
signer.Tabs.SignerAttachmentTabs = new List<SignerAttachment>();
after which we need an attachment to add to it
SignerAttachment signDoc = new SignerAttachment();
signDoc.TabLabel = "Attach your Other Doc";
signDoc.DocumentId = "1";
signDoc.TabId = "1";
signDoc.PageNumber = "1";
And finally we add it to the tabs
signer.Tabs.SignerAttachmentTabs.Add(signDoc);

Related

Docusign SDK C# Radio Button Group ,Docusign The RecipientId specified in the tab element does not refer to a recipient of this envelope

I am getting this Issue on Docusign Radio group.I am
Docusign The RecipientId specified in the tab element does not refer to a recipient of this envelope. Tab refers to RecipientId 88183597-41B3-42C5-9E48-D1A4D5C3F262 who is not present.
This Works Fine:
return new RadioGroup
{
GroupName= Guid.NewGuid().ToString(),
DocumentId = documentId,
RecipientId = userId,
};
This doesn't work .
return new RadioGroup
{
GroupName= Guid.NewGuid().ToString(),
DocumentId = documentId,
RecipientId = userId,
Radios= new List<Radio>()
{
new Radio(){ PageNumber="1",Selected = "true",Value ="X",XPosition = "300", YPosition = "75" } ,
// new Radio(){ PageNumber="1",Selected = "false",Value ="Y",XPosition = "350", YPosition = "75" }
},
};
I am setting Signer Tabs as
signer.Tabs = new Tabs
{
SignHereTabs = signers,
InitialHereTabs = initialsHere,
DateSignedTabs = dateSinged,
ApproveTabs = approves,
DeclineTabs = declines,
FullNameTabs = fullNames,
CheckboxTabs = checkBoxes,
RadioGroupTabs = radiobuttongroups,
TextTabs = textboxes,
};
After Long debugging came to know that DocuSign converts Recipient Ids to lower case and somehow it was not matching TAB's Recipient ID, Had to convert Recipient IDs of signer and tabs to lower.

Can you have a returnUrlRequest for a sender view generated from a bulk send?

I'm trying to create a workflow where a user can do a bulk send through docusign within my application. They would select the clients they want to send forms to for a signature, be presented with a sender view to specify what fields they require, send it off, then have it post back to my application in order to generate emails for embedded signing. However, currently, it doesn't return back to my application after the user has sent off the bulk request despite the return url request being set. Is this currently not possible with a bulk send request?
The following is just some code to generate the sender view url:
// Create envelope definition
var envelopeDefinition = new EnvelopeDefinition
{
EmailSubject = documentDesc,
Documents = new List<Document>(),
Recipients = new Recipients { Signers = new List<Signer> {
new Signer
{
Name = "Multi Bulk Recipient::signer",
Email = "multiBulkRecipients-signer#docusign.com",
RoleName = "signer",
RoutingOrder = "1",
Status = "sent",
DeliveryMethod = "Email",
RecipientId = "1",
RecipientType = "signer"
}
} },
CustomFields = new CustomFields()
{
TextCustomFields = new List<TextCustomField>()
{
new TextCustomField() {Name = "Client", Value = _config.DatabaseName},
new TextCustomField() {Name = "Server", Value = _config.DatabaseServer},
new TextCustomField() {Name = "DocId", Value = documentId.ToString()}
}
},
EnvelopeIdStamping = "true",
};
// Read a file from disk to use as a document.
byte[] fileBytes = File.ReadAllBytes("test.pdf");
// Add a document to the envelope
Document doc = new Document();
doc.DocumentBase64 = System.Convert.ToBase64String(fileBytes);
doc.Name = "TestFile.pdf";
doc.DocumentId = "1";
envDef.Documents = new List<Document>();
envDef.Documents.Add(doc);
// Add each recipient and add them to the envelope definition
var recipients = new List<BulkSendingCopyRecipient>();
var recipients = new List<BulkSendingCopyRecipient> {
new BulkSendingCopyRecipient
{
Name = "Bob Ross",
Email = "bobross#happymistakes.com",
ClientUserId = "1234",
CustomFields = new List<string>()
{
"A custom field for internal use"
},
RoleName = "signer"
},
new BulkSendingCopyRecipient
{
Name = "Fred Rogers",
Email = "mrrogers#neighborhood.com",
ClientUserId = "5678",
CustomFields = new List<string>()
{
"Another custom field for internal use"
},
RoleName = "signer"
}
};
var bulkSendingCopy = new BulkSendingCopy
{
Recipients = recipients
};
var bulkCopies = new List<BulkSendingCopy>
{
bulkSendingCopy
};
var bulkSendingList = new BulkSendingList
{
BulkCopies = bulkCopies
};
bulkSendingList.Name = "A document name";
envelopeDefinition.Status = "created";
var envelopesApi = new EnvelopesApi(config);
var bulkEnvelopesApi = new BulkEnvelopesApi();
var createBulkListResult = bulkEnvelopesApi.CreateBulkSendList(AccountId, bulkSendingList);
envelopeDefinition.CustomFields.TextCustomFields.Add(
new TextCustomField
{
Name = "mailingListId",
Required = "false",
Show = "false",
Value = createBulkListResult.ListId //Adding the BULK_LIST_ID as an Envelope Custom Field
}
);
var envelopeSummary = envelopesApi.CreateEnvelope(AccountId, envelopeDefinition);
var options = new ReturnUrlRequest
{
ReturnUrl = HttpContext.Current.Request.Url.Scheme + "://" +
HttpContext.Current.Request.Url.Authority +
HttpContext.Current.Request.ApplicationPath +
"/SIP/ConfirmTagSendAndPublish.aspx?idockey=" + documentId
};
var senderView = envelopesApi.CreateSenderView(AccountId, envelopeSummary.EnvelopeId, options);
var senderViewInfo = new string[2];
senderViewInfo[0] = senderView.Url;
senderViewInfo[1] = envelopeSummary.EnvelopeId;
return senderViewInfo;
When the sender view comes up and you hit send it just takes me to the Sent tab in docusign
What I see after send
So in order for you to do the scenario you're asking to do, you will have to take a slightly different approach:
Generate a regular envelope in draft mode with the things you need.
Have user interact with it in embedded sending experience.
Generate a bulk using the CreateBulkList() method based on the envelope from #2 and the users you add like in your code.
(to do #3 you may need to copy custom fields etc. from the initial envelope to the one used for custom fields)

To set document visibility for multiple recipient with multiple document via docusign API

I am trying to implement the document visibility of docuSign.suppose i have two document(Document A and Document B) and I have two CC person (Person A and Person B)
and i am trying to hide the document from CC person (who receive a copy of document). Document B from Person A and Document A from Person B.
but when i try this from DocuSign portal it is working fine but when i implement the code for this then the visibility setting of document is not working.
public void docusign(string path, string recipientName, string recipientEmail, string EnvelopeId)
{
ApiClient apiClient = new ApiClient("https://demo.docusign.net/restapi");
Configuration.Default.ApiClient = apiClient;
//Verify Account Details
string accountId = loginApi(credential.UserName, credential.Password);
// Read a file from disk to use as a document.
byte[] fileBytes = System.IO.File.ReadAllBytes(path);
byte[] fileBytes1 = System.IO.File.ReadAllBytes(#"Path");
EnvelopeDefinition envDef = new EnvelopeDefinition();
envDef.EmailSubject = "Please sign this doc";
//Here i am adding the document
Document doc = new Document();
doc.DocumentBase64 = System.Convert.ToBase64String(fileBytes);
doc.Name = Path.GetFileName(path);
doc.DocumentId = "1";
doc.TransformPdfFields = "true";
Document doc1 = new Document();
doc1.DocumentBase64 = System.Convert.ToBase64String(fileBytes1);
doc1.Name = "Test 2-converted -converted.pdf";// Path.GetFileName(path);
doc1.DocumentId = "2";
//Adding CC person
List<CarbonCopy> oo = new List<CarbonCopy>();
oo.Add(new CarbonCopy
{
RecipientId = "1",
RoutingOrder = "1",
Name = "darpan",
Email = "xyz1#gmail.com",
DocumentVisibility = new List<DocumentVisibility>() { new DocumentVisibility { Visible = "false", DocumentId = "2", RecipientId = "1" } },
});
oo.Add(new CarbonCopy
{
RecipientId = "2",
RoutingOrder = "2",
Name = "mohini",
Email = "xyz2#gmail.com",
DocumentVisibility= new List<DocumentVisibility>() { new DocumentVisibility { Visible = "false", DocumentId = "1", RecipientId = "2" } },
});
envDef.Recipients = new DocuSign.eSign.Model.Recipients();
envDef.Recipients.CarbonCopies = oo;
envDef.Status = "Sent";
// |EnvelopesApi| contains methods related to creating and sending Envelopes (aka signature requests)
EnvelopesApi envelopesApi = new EnvelopesApi();
EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef);
you need to add this to your code:
envDef.EnforceSignerVisibilty = "true";
I found the issue. It because I am not listing all document in document visibility list.
Like I have two document in envelop and while adding document visibility list.
I am only adding document that need visibility to false.
Document visibility list should have all the document in list with visibility setting.
What I am doing
DocumentVisibility = new List<DocumentVisibility>() { new DocumentVisibility { Visible = "false", DocumentId = "2", RecipientId = "1"}}
Correct way is
DocumentVisibility = new List<DocumentVisibility>() { new DocumentVisibility { Visible = "false", DocumentId = "2", RecipientId = "1" },new DocumentVisibility { Visible = "true", DocumentId = "1", RecipientId = "1" }}

Add multiple documents to envelope using c# sdk using Docusign API

I have a template in Docusign that I need to send to joe#acme.com
However Joe is responsible for managing 10 clients and instead of me sending Joe 10 separate envelopes for him to sign I want to send Joe 1 envelope with 10 documents and Joe needs to sign all 10 document in the envelope. The documents are identical except for the different data filled in the text field of the template
I am using the C# SDK provided by Docusign and I can send one document in an envelope using EnvelopeDefinition class and TemplateRole class but am lost as to how to create 10 documents in an envelope
The following recipe does it but it is in python and uses the REST API with which I am not sure how to translate to the C# SDK equivalent
https://www.docusign.com/developer-center/recipes/send-multiple-docs
You can use compositeTemplates and reuse the same server template multiple times in the envelope. The below code uses the same server Template and repeats it 10 times in the envelope. See full example here
public void CreateEnvelope()
{
var envDef = new EnvelopeDefinition()
{
EmailSubject = "Envelope with multiple documents",
Status = "sent",
CompositeTemplates = new List<CompositeTemplate>()
};
for (int docNumber = 1; docNumber <= 10; docNumber++)
{
var compostiteTemplate = BuildCompositeTemplate(docNumber.ToString());
envDef.CompositeTemplates.Add(compostiteTemplate);
}
EnvelopesApi envelopesApi = new EnvelopesApi();
EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef);
Console.WriteLine(envelopeSummary);
}
public CompositeTemplate BuildCompositeTemplate(string docNumber)
{
string serverTemplateId = "";//Add your server template ID here
return new CompositeTemplate()
{
ServerTemplates = new List<ServerTemplate>()
{
new ServerTemplate()
{
TemplateId = serverTemplateId,
Sequence = docNumber
}
},
InlineTemplates = new List<InlineTemplate>()
{
new InlineTemplate()
{
Sequence = docNumber,
Recipients = new Recipients()
{
Signers = new List<Signer>()
{
new Signer()
{
Email = "Janedoe#acme.com",
Name = "Jane Doe",
RecipientId = "1",
RoleName = "Signer1",
Tabs = new Tabs()
{
TextTabs = new List<Text>()
{
new Text()
{
DocumentId = docNumber,
PageNumber = "1",
XPosition = "100",
YPosition = "100",
Width = 120,
Value = "Some Tab Value " + docNumber
}
}
}
}
}
}
}
}
}
}
There is the property Documents in the class EnvelopeDefinition, where you can add multiply documents.
I use the REST API Explorer from DocuSign when I want to check how to implement a feature.
enDef = new EnvelopeDefinition();
doc = new Document();
doc.DocumentBase64 = System.Convert.ToBase64String(System.IO.File.ReadAllBytes(filename));
doc.Name = DocName;
doc.DocumentId = "1"; // increment this
enDef.Documents = new List<Document>();
enDef.Documents.Add(doc);
Added
For multiply template roles also exists a property called TemplateRoles in the EnvelopeDefinition. There you can add more than one.
tempRole = new TemplateRole();
tempRole.Name = Rolename;
enDef.TemplateRoles = new List<TemplateRole>();
enDef.TemplateRoles.Add(tempRole);`

Adding document to docusign envelope always return false

I'm using the following code to try to add a pdf document to an existing template with multiple documents using the AddDocument function of the c# API but the result is always false. The template is succesfully sent with all the preset documents sent correctly. How do I correctly add the pdf document? I have to add the pdf document using code because this particular document is different every time we send the template. I have tested GetIPS function and it returned the byte[] for the pdf document so I know that's not the issue.
Here are my codes
byte[] ips = GetIPS("");
RestSettings.Instance.DocuSignAddress = "https://demo.docusign.net";
RestSettings.Instance.WebServiceUrl = RestSettings.Instance.DocuSignAddress + "/restapi/v2";
RestSettings.Instance.IntegratorKey = integratorKey;
DocuSign.Integrations.Client.Account account = new DocuSign.Integrations.Client.Account();
account.Email = username;
account.Password = password;
var loginResult = account.Login();
Template template = new Template();
template.TemplateId = templateId;
template.Login = account;
template.EmailSubject = emailSubject;
template.EmailBlurb = emailMessage;
var documents = template.GetDocuments();
TemplateRole tr = new TemplateRole();
var roles = new List<TemplateRole>();
//Handle Primary Client
roles.Add(new TemplateRole
{
roleName = "Primary Client",
name = primaryClientName,
email = primaryClientEmail,
tabs = new RoleTabs
{
textTabs = new RoleTextTab[] {
new RoleTextTab {
tabLabel = "FeeEffectiveDate",
value = effectiveDate
},
new RoleTextTab {
tabLabel = "FeePercentage",
value = fee
}
}
},
});
if (secondaryClientName.Trim().Length != 0)
{
roles.Add(new TemplateRole
{
roleName = "Secondary Client",
name = secondaryClientName,
email = secondaryClientEmail,
});
}
roles.Add(new TemplateRole
{
roleName = "President",
name = presidentName,
email = presidentEmail,
});
roles.Add(new TemplateRole
{
roleName = "Css",
name = cssName,
email = cssEmail,
});
template.TemplateRoles = roles.ToArray<TemplateRole>();
template.Status = "sent";
//The following code always return false
bool status = template.AddDocument(ips, "IPS.pdf", 1);
var result = template.Create();
In order to use the AddDocument function, an envelope must be in draft state (as you can also see in the remarks for this function in the source code). Therefore, in your case, you must first create a draft envelope (by changing the envelope status to "created"), then invoke the AddDocument function, and finally update the envelope status to "sent" to send the envelope.
For example:
.
.
.
template.Status = "created";
var result = template.Create();
bool status = template.AddDocument(ips, "IPS.pdf", 2);
template.Status = "sent";
result = template.UpdateStatus();
Note that the document index is the document ID, and is must be different from the IDs of the existing documents in your template. Otherwise, an existing document that has the same ID number, will be replaced by the new document.

Categories