问题
I have created a template and added two role signer1 & signer2.I am creating envelopes & adding signers on fly using this template.Its working fine.In some case,admin user don't know 2nd signer and adding only first signer and envelope is created with single signer.Once envelope is created,Now I want to add 2nd signer on envelope.I am using C# docusign client, I tried
{
var templateInfo = await envelopesApi.ListTemplatesAsync(await AccountAsync(), envelopeId, new EnvelopesApi.ListTemplatesOptions { include = "applied" }); //fetching template id
foreach (var template in templateInfo.Templates)
{
var templateRecipients = await templatesApi.ListRecipientsAsync(await AccountAsync(), template.TemplateId, new ListRecipientsOptions { includeTabs = "true" }); //fetching tabs assigned to roles in templatea
Var signer= templateRecipients.Signers.FirstOrDefault(w => w.RoleName.ToLower() == signer.SigningRole.ToLower())
Recipients.Signers = signers.Aggregate(new List<Signer>(), (newSigners, signer) =>
{
string recipeintId = Guid.NewGuid().ToString();
Tabs tabs = templateSigner.Tabs;
Tabs newTabs = new Tabs();
var newSigner = new Signer
{
Email = signer.Email,
Name = signer.FullName,
RoleName = signer.SigningRole,
//ClientUserId = signer.Email,
RecipientId = recipeintId, //Int or Guid expected
Tabs =BuildRecipientTabs(recipeintId,signer?.Tabs) ; //copying tabs
};
newSigners.Add(newSigner);
return newSigners;
});
var something = await envelopesApi.UpdateRecipientsAsync( AccountId, envelopeId, recipients);
}
//
private Tabs BuildRecipientTabs(string recipientId, Tabs tabs)
{
Tabs newTab = new Tabs();
if (tabs.ApproveTabs != null)
{
tabs.ApproveTabs.ForEach(w => { if (w != null) { w.RecipientId = recipientId; } });
}
if (tabs.CheckboxTabs != null)
{
tabs.CheckboxTabs.ForEach(w => { if (w != null) { w.RecipientId = recipientId; } });
}
if (tabs.DateTabs != null)
{
tabs.DateTabs.ForEach(w => { if (w != null) { w.RecipientId = recipientId; } });
}
if (tabs.DateSignedTabs != null)
{
tabs.DateSignedTabs.ForEach(w => { if (w != null) { w.RecipientId = recipientId; } });
}
if (tabs.DeclineTabs != null)
{
tabs.DeclineTabs.ForEach(w => { if (w != null) { w.RecipientId = recipientId; } });
}
if (tabs.EmailAddressTabs != null)
{
tabs.EmailAddressTabs.ForEach(w => { if (w != null) { w.RecipientId = recipientId; } });
}
if (tabs.EmailTabs != null)
{
tabs.EmailTabs.ForEach(w => { if (w != null) { w.RecipientId = recipientId; } });
}
if (tabs.EnvelopeIdTabs != null)
{
tabs.EnvelopeIdTabs.ForEach(w => { if (w != null) { w.RecipientId = recipientId; } });
}
if (tabs.FullNameTabs != null)
{
tabs.FullNameTabs.ForEach(w => { if (w!=null) { w.RecipientId = recipientId;}});
}
if (tabs.FirstNameTabs != null)
{
tabs.FirstNameTabs.ForEach(w => { if (w != null) { w.RecipientId = recipientId; } });
}
if (tabs.FormulaTabs != null)
{
tabs.FormulaTabs.ForEach(w => { if (w != null) { w.RecipientId = recipientId; } });
}
if (tabs.InitialHereTabs != null)
{
tabs.InitialHereTabs.ForEach(w => { if (w != null) { w.RecipientId = recipientId; } });
}
if (tabs.LastNameTabs != null)
{
tabs.LastNameTabs.ForEach(w => { if (w != null) { w.RecipientId = recipientId; } });
}
if (tabs.ListTabs != null)
{
tabs.ListTabs.ForEach(w => { if (w != null) { w.RecipientId = recipientId; } });
}
if (tabs.NotarizeTabs != null)
{
tabs.NotarizeTabs.ForEach(w => { if (w != null) { w.RecipientId = recipientId; } });
}
if (tabs.NoteTabs != null)
{
tabs.NoteTabs.ForEach(w => { if (w != null) { w.RecipientId = recipientId; } });
}
if (tabs.NumberTabs != null)
{
tabs.NumberTabs.ForEach(w => { if (w != null) { w.RecipientId = recipientId; } });
}
if (tabs.PolyLineOverlayTabs != null)
{
tabs.PolyLineOverlayTabs.ForEach(w => { if (w != null) { w.RecipientId = recipientId; } });
}
if (tabs.RadioGroupTabs != null)
{
tabs.RadioGroupTabs.ForEach(w => { if (w != null) { w.RecipientId = recipientId; } });
}
if (tabs.SignerAttachmentTabs != null)
{
tabs.SignerAttachmentTabs.ForEach(w => { if (w != null) { w.RecipientId = recipientId; } });
}
if (tabs.SignHereTabs != null)
{
tabs.SignHereTabs.ForEach(w => { if (w != null) { w.RecipientId = recipientId; w.TabId = null; } });
}
if (tabs.SmartSectionTabs != null)
{
tabs.SmartSectionTabs.ForEach(w => { if (w != null) { w.RecipientId = recipientId; } });
}
if (tabs.SsnTabs != null)
{
tabs.SsnTabs.ForEach(w => { if (w != null) { w.RecipientId = recipientId; } });
}
if (tabs.TitleTabs != null)
{
tabs.TitleTabs.ForEach(w => { if (w != null) { w.RecipientId = recipientId; } });
}
if (tabs.TextTabs != null)
{
tabs.TextTabs.ForEach(w => { if (w != null) { w.RecipientId = recipientId; w.TabId=null; } });
}
if (tabs.TabGroups != null)
{
tabs.TabGroups.ForEach(w => { if (w != null) { w.RecipientId = recipientId; } });
}
if (tabs.ViewTabs != null)
{
tabs.ViewTabs.ForEach(w => { if (w != null) { w.RecipientId = recipientId; } });
}
if (tabs.ZipTabs != null)
{
tabs.ZipTabs.ForEach(w => { if (w != null) { w.RecipientId = recipientId; } });
}
return tabs;
}
its adding recipients but not associated with template role.Can anyone suggest how recipients can be assigned template role?
回答1:
I just found solution for this requirement.Tabs are not created or updated using UpdateRecipientsAsync or CreateRecipientsAsync
It worked using CreateTabAsync..
//build recipients
recipients.Signers = signers.Aggregate(new List<Signer>(), (newSigners, signer) =>
{
string recipeintId = Guid.NewGuid().ToString();
var newSigner = new Signer
{
Email = signer.Email,
Name = signer.FullName,
RoleName = signer.SigningRole,
ClientUserId = signer.Email,
RecipientId = recipeintId //Int or Guid expected
};
newSigners.Add(newSigner);
return newSigners;
});
var addedRecipient = await envelopesApi.CreateRecipientAsync(await AccountAsync(), envelopeId, recipients); //adding recipients
var templateInfo = await envelopesApi.ListTemplatesAsync(await AccountAsync(), envelopeId, new EnvelopesApi.ListTemplatesOptions { include = "applied" });
//envelope is created using one template only
var templateRecipients = await templatesApi.ListRecipientsAsync(await AccountAsync(), templateInfo.Templates.FirstOrDefault().TemplateId, new ListRecipientsOptions { includeTabs = "true" });
foreach (var signer in recipients.Signers)
{
Signer templateSigner = templateRecipients.Signers.FirstOrDefault(w => w.RoleName.ToLower() == signer.RoleName.ToLower());
Tabs tabs =BuildRecipientTabs(signer.RecipientId, templateSigner.Tabs);
var t= await envelopesApi.CreateTabsAsync(await AccountAsync(), envelopeId, signer.RecipientId, tabs);
}
回答2:
the recipients object include recipients and if you make sure that the role matches to what's in the template - it should work. Please share your entire code for further assistance.
来源:https://stackoverflow.com/questions/57726510/add-signer-on-template-based-docusign-envelope