Need help prefilling DocuSign template document fields with dynamic data before sending envelope

I’m currently working on a project where I need to prefill DocuSign template document fields with dynamic data before sending the envelope. I’ve tried multiple approaches but haven’t been successful so far.
Current approach:
I’m using the DocuSign eSign Ruby SDK to interact with the DocuSign API. Here’s a simplified version of my code:

 def send_data_using_template(access_token)
    api_client = DocuSign_eSign::ApiClient.new
    api_client.default_headers['Authorization'] = 'Bearer ' + access_token

    templates_api = DocuSign_eSign::TemplatesApi.new(api_client)
    envelopes_api = DocuSign_eSign::EnvelopesApi.new(api_client)
    options = DocuSign_eSign::ListTemplatesOptions.new

    options.search_text = "Example document generation template"

    results = templates_api.list_templates(ENV['DOCUSIGN_ACCOUNT_ID'], options)
    template = results.envelope_templates.find { |template| template.name == "Example document generation template" }
    byebug
    template_id = template.template_id if template

    byebug
    current_user_name = "Alia"
    current_user_email = "[email protected]"

    envelope_definition = DocuSign_eSign::EnvelopeDefinition.new({
                        status: 'sent',
                        templateId: template_id,
                        emailSubject:" EMAIL_SUBJECT"
                      })

    text_tab = DocuSign_eSign::Text.new
    text_tab.tab_label = 'Text 9104f26a-e0fc-4b18-9843-07944aaedcda'
    text_tab.value = 'Jabberwocky!'

    tabs = DocuSign_eSign::Tabs.new
    tabs.text_tabs = [text_tab]

    signer = DocuSign_eSign::TemplateRole.new({
      email: current_user_email,
      name: current_user_name,
      roleName: 'signer',
      tabs: tabs     
    })
        
    envelope_definition.template_roles = [signer]

    envelopes_api = DocuSign_eSign::EnvelopesApi.new api_client
    response = envelopes_api.create_envelope ENV['DOCUSIGN_ACCOUNT_ID'], envelope_definition
  

    if response.envelope_id.present?
      puts "Envelope created successfully"
      loop do
        envelope_status = envelopes_api.get_envelope ENV['DOCUSIGN_ACCOUNT_ID'], response.envelope_id
        puts "Envelope status: #{envelope_status.status}.................................."
        break if ['completed', 'signed'].include?(envelope_status.status)
        sleep 5
      end

      response = HTTParty.get(
              "https://demo.docusign.net/restapi/v2.1/accounts/#{ENV['DOCUSIGN_ACCOUNT_ID']}/envelopes/#{response.envelope_id}/documents/combined",
              headers: { "Authorization" => "Bearer #{access_token}" }
            )

      if response.success?
        timestamp = Time.now.strftime("%Y%m%d%H%M%S")
        signed_document_path = "config/signed_document_#{timestamp}.pdf"
        File.open(signed_document_path, "wb") { |file| file.write(response.body) }
        puts "Signed document saved successfully at #{signed_document_path}"
      else
        puts "Error retrieving signed document: #{response}"
      end
    else
      puts "Error creating envelope: #{response}"
    end
  end

I’ve explored the following resources and approaches:

  1. DocuSign documentation on prefilling tabs: Link

  2. Stack Overflow threads: Thread 1, Thread 2

However, I haven’t been able to successfully prefill the template fields with dynamic data using these methods.

New contributor

Hira is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật