You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用DocuSign C# SDK批量发送时自定义字段不存在问题求助

解决DocuSign C# SDK批量发送自定义字段报错问题

问题描述

使用DocuSign C# SDK实现批量发送功能,需为每个副本设置2个自定义字段用于后续DocuSign Connect事件通知。当前使用无自定义字段的模板进行批量操作,非批量发送时直接将字段添加到信封定义可正常工作,但批量发送时为每个BulkCopy设置字段后出现如下报错:

Error calling CreateBulkSendRequest: {
"envelopeOrTemplateId":"c15eddc4-a4ca-495d-8d19-662b0e7194a4",
"batchId":"00000000-0000-0000-0000-000000000000",
"batchSize":"1","totalQueued":"0","queueLimit":"2000","errors":["BULK_SEND_ENVELOPE_CUSTOM_FIELD_DOES_NOT_EXIST_IN_ENVELOPE"],
"errorDetails":["Custom field CustomField1 does not exist in the envelope.","Custom field CustomField2 does not exist in the envelope."]}

当前流程:先创建包含每个BulkCopy自定义字段设置的BulkSendList,再将其与templateId一同传入CreateBulkSendRequest。非批量发送无需单独创建字段,但批量发送缺少字段创建步骤,且未在BulkEnvelopesApi中找到对应方法,模板相关文档缺失。

非批量设置代码

envelopeDefinition.CustomFields = new CustomFields
{
    TextCustomFields = new List<TextCustomField>
    {
        new TextCustomField
        {
            Name = "CustomField1",
            Value = customField1Value
        },
        new TextCustomField
        {
            Name = "CustomField2",
            Value = customField2Value
        }
    }
};

批量设置代码(每个BulkCopy)

CustomFields = new List<BulkSendingCopyCustomField>
{
    new BulkSendingCopyCustomField
    {
        Name = "CustomField1",
        Value = customField1Value
    },
    new BulkSendingCopyCustomField
    {
        Name = "CustomField2",
        Value = customField2Value
    }
}

流程代码

var list = _bulkEnvelopesApi.CreateBulkSendList(accountId, bulkSendingList);
BulkSendResponse response = _bulkEnvelopesApi.CreateBulkSendRequest(accountId, list.ListId, new BulkSendRequest()
{
    EnvelopeOrTemplateId = templateId,
});

解决方案

方案1:预先给模板添加自定义字段

批量发送时,自定义字段必须预先存在于模板或基础信封中。你可以通过DocuSign控制台编辑目标模板,添加CustomField1和CustomField2两个文本自定义字段(字段值可留空)。完成后再使用该模板发起批量发送,即可正常为每个BulkCopy设置字段值。

方案2:基于模板创建草稿信封并添加字段,再用信封ID批量发送

如果不想修改模板,可先基于模板创建一个草稿信封,在信封定义中添加自定义字段,再用这个草稿信封的ID发起批量请求,替代原模板ID。代码示例如下:

// 1. 基于模板创建草稿信封,添加自定义字段(值留空)
var envelopeApi = new EnvelopesApi();
var envelopeDefinition = new EnvelopeDefinition
{
    TemplateId = templateId,
    Status = "created", // 设置为草稿状态
    CustomFields = new CustomFields
    {
        TextCustomFields = new List<TextCustomField>
        {
            new TextCustomField { Name = "CustomField1", Value = "" },
            new TextCustomField { Name = "CustomField2", Value = "" }
        }
    }
};
var createdEnvelope = envelopeApi.CreateEnvelope(accountId, envelopeDefinition);
var envelopeId = createdEnvelope.EnvelopeId;

// 2. 创建批量发送列表,为每个副本设置字段值
var bulkSendingList = new BulkSendingList
{
    BulkCopies = new List<BulkSendingCopy>
    {
        new BulkSendingCopy
        {
            // 配置收件人等必要信息
            CustomFields = new List<BulkSendingCopyCustomField>
            {
                new BulkSendingCopyCustomField { Name = "CustomField1", Value = customField1Value },
                new BulkSendingCopyCustomField { Name = "CustomField2", Value = customField2Value }
            }
        }
        // 添加其他批量副本
    }
};
var list = _bulkEnvelopesApi.CreateBulkSendList(accountId, bulkSendingList);

// 3. 使用草稿信封ID发起批量请求
BulkSendResponse response = _bulkEnvelopesApi.CreateBulkSendRequest(accountId, list.ListId, new BulkSendRequest()
{
    EnvelopeOrTemplateId = envelopeId, // 替换为草稿信封ID
});

内容的提问来源于stack exchange,提问作者Flashcap

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 22:34:58