简体   繁体   English

将文档添加到docusign信封中始终返回false

[英]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. 我正在使用以下代码尝试使用c#API的AddDocument函数将pdf文档添加到具有多个文档的现有模板中,但是结果始终为false。 The template is succesfully sent with all the preset documents sent correctly. 成功发送模板,正确发送了所有预设文档。 How do I correctly add the pdf document? 如何正确添加pdf文档? I have to add the pdf document using code because this particular document is different every time we send the template. 我必须使用代码添加pdf文档,因为每次我们发送模板时,此特定文档都是不同的。 I have tested GetIPS function and it returned the byte[] for the pdf document so I know that's not the issue. 我已经测试了GetIPS函数,它返回了pdf文档的byte [],所以我知道这不是问题。

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 ). 为了使用AddDocument函数,信封必须处于草稿状态(您也可以在源代码中的该函数的注释中看到)。 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. 因此,在您的情况下,您必须首先创建草稿信封(通过将信封状态更改为“已创建”),然后调用AddDocument函数,最后将信封状态更新为“已发送”以发送信封。

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. 请注意,文档索引是文档ID,并且必须与模板中现有文档的ID不同。 Otherwise, an existing document that has the same ID number, will be replaced by the new document. 否则,具有相同ID号的现有文档将被新文档替换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM