I am working on an application that uses DocuSign signing in an iframe, housed within a proprietary web app. Signers are able to access the embedded iframe signing view within the same web app.
It was developed without templates in mind. I have implemented the use of templates with building an envelopeDefinition containing the templateKey and respective TemplateRoles. The same "CreateEnvelope" function is called for both non-template and template envelopes, but with different arguments. The Setup page loads in with the template already selected, roles defined, and fields set. The issue arises when the "send" button is clicked.
Without a template, there is no email sent to the signers. It allows for the signers to do so in an embedded form in the proprietary app I am working with. Here is the function used to create an envelope without a template:
public EnvelopeSummary CreateEnvelope(string filePath, string username = null, string emailSubject = null, string brandID = null,List<Models.Recipient> recipients = null)
{
EnvelopeDefinition envelopeDef = new EnvelopeDefinition
{
Status = "created",
EmailSubject = emailSubject,
BrandId = brandID
};
if (recipients != null)
{
List<Signer> signers = recipients.Select(x => new Signer() { Email = x.Email, Name = x.UserName, ClientUserId = x.RecipientID > 50 ? x.RecipientID.ToString() : null, RecipientId = x.RouteOrder.ToString(), RoutingOrder = x.RouteOrder.ToString() }).ToList();
envelopeDef.Recipients = new Recipients() { Signers = signers };
}
return Factory.GetEnvelopesApi(DocuSignConfig).CreateEnvelope(accountId: Helpers.SettingsHelper.AccountID, envelopeDefinition: envelopeDef, options: null);
}
With a template applied, signers are sent an email for an external signature before the workflow has returned to the proprietary app through the return URL of the SenderView. Here is the code used to create an envelope with a template:
public EnvelopeSummary CreateTemplateEnvelope(string filePath,
List<DataModels.GetRole> roles = null,
DataModels.GetTemplate template = null,
string username = null,
string emailSubject = null,
string brandID = null,
List<Models.Recipient> recipients = null)
{
EnvelopeDefinition envelopeDef = new EnvelopeDefinition
{
Status = "created",
EmailSubject = emailSubject,
BrandId = brandID,
TemplateId = template.TemplateKey
};
if (roles != null && recipients != null)
{
List<Signer> signers = recipients.Select(x => new Signer() { Email = x.Email, Name = x.UserName, ClientUserId = x.RecipientID > 50 ? x.RecipientID.ToString() : null, RecipientId = x.RouteOrder.ToString(), RoutingOrder = x.RouteOrder.ToString() }).ToList();
var templateRoles = new List<TemplateRole>();
int counter = 0;
foreach (Signer signr in signers)
{
TemplateRole thisSigner = new TemplateRole();
thisSigner.Email = signers[counter].Email;
thisSigner.Name = signers[counter].Name;
thisSigner.RoleName = roles[counter].RoleName;
templateRoles.Add(thisSigner);
counter++;
}
envelopeDef.TemplateRoles = templateRoles;
}
return Factory.GetEnvelopesApi(DocuSignConfig).CreateEnvelope(accountId: Helpers.SettingsHelper.AccountID,
envelopeDefinition: envelopeDef,
options: null);
}
The primary differences are that the template version includes the templateKey, and it uses TemplateRoles rather than Recipients. The template code is a bit more rough than I'd like for a final product, but it's a work in progress just trying to get it running. Does anyone have insight as to how or if it might be possible to create an Envelope and then retain the ability to use embedded signing? Thank you for any help.
EDIT: Solved
As mentioned in the comments to the answer, the issue was solved by properly setting the ClientUserId of each template role based on the Recipient's value for it. This allowed for embedded signing with the template role signers.