I want to be able to fill in template tabs but no matter what I try I cannot find how to do it. I have looked at the example code from the git hub and every one of the API dictionaries I could find for DocuServ. I want to be able to fill in the text fields I placed in a template. They all have different ids. I have tried to edit their start examples but to no avail.

Here is the code I am trying. Atleast this will give me the template I am after.

    @classmethod
    #ds-snippet-start:eSign2Step2
    def make_envelope(cls, args, doc_docx_path, doc_pdf_path):
    
        # Create the signer recipient model
        signer1 = Signer(
            email=args["signer_email"],
            name=args["signer_name"],
            recipient_id="1",
            routing_order="1",
            role_name = "Parent"
        )
                # Create the cc recipient
        cc1 = CarbonCopy(
            email=args["cc_email"],
            name=args["cc_name"],
            role_name="Representative",
            recipient_id="2"
        )
      # Recipients object:
        recipients_server_template = Recipients(
            carbon_copies=[cc1],
            signers=[signer1]
        )
        # Next, create the second composite template that will
        # include the new document.
        #
        # Create the signer recipient for the added document
        # starting with the tab definition:
        sign_here1 = SignHere(
            anchor_string="Agreed and signed:",
            anchor_y_offset="10",
            anchor_units="pixels",
            anchor_x_offset="20"
        )
        signer1_tabs = Tabs(sign_here_tabs=[sign_here1])

        # Create Signer definition for the added document
        signer1_added_doc = Signer(
            email=args["signer_email"],
            name=args["signer_name"],
            role_name="signer",
            recipient_id="1",
            client_user_id=args["signer_client_id"],
            tabs=signer1_tabs
        )
        recipients_added_doc = Recipients(
            carbon_copies=[cc1], signers=[signer1_added_doc])
        
        # Add a document        
        with open(path.join(demo_docs_path, "MacBook Release A.docx"), "rb") as file:
            docA_docx_bytes = file.read()
        docA_b64 = base64.b64encode(docA_docx_bytes).decode("ascii")
        
        documentA = Document(  # create the DocuSign document object
            document_base64=docA_b64,
            name="Laptop Release",  # can be different from actual file name
            file_extension="docx",  # many different document types are accepted
            document_id="1"  # a label used to reference the doc
        )
        # The order in the docs array determines the order in the envelope
     
        # Create a composite template for the Server template + roles
        comp_template1 = CompositeTemplate(
            composite_template_id="1",
            server_templates=[
                ServerTemplate(sequence="1", template_id="6f3a0b76-2329-4456-89a0-afc13a52aa19")
            ],
            # Add the roles via an inlineTemplate
            inline_templates=[
                InlineTemplate(sequence="2",
                               recipients=recipients_server_template)
            ]
        )
        # Create a composite template for the added document
       # comp_template2 = CompositeTemplate(
        #    composite_template_id="2",
         #   # Add the recipients via an inlineTemplate
          #  inline_templates=[
           #     InlineTemplate(sequence="1", recipients=recipients_added_doc)
            #],
           #document=documentA
        #)
        # The envelope has two recipients.
        # recipient 1 - signer
        # recipient 2 - cc
        # The envelope will be sent first to the signer.
        # After it is signed, a copy is sent to the cc person.

        env = EnvelopeDefinition(
            email_subject="Please sign this document set to receive your Laptop",
            composite_templates=[comp_template1] # , comp_template2]
        )
        env.documents = [documentA] 
 

 
        # Create signHere fields (also known as tabs) on the documents,
        # We"re using anchor (autoPlace) positioning
        #
        # The DocuSign platform searches throughout your envelope"s
        # documents for matching anchor strings. So the
        # signHere2 tab will be used in both document 2 and 3 since they
        # use the same anchor string for their "signer 1" tabs.
        sign_here1 = SignHere(
            anchor_string="Signature:",
            anchor_units="pixels",
            anchor_y_offset="10",
            anchor_x_offset="200"
        )

        sign_here2 = SignHere(
            anchor_string="/sn1/",
            anchor_units="pixels",
            anchor_y_offset="10",
            anchor_x_offset="20"
        )

        """
        Creates envelope
        args -- parameters for the envelope:
        signer_email, signer_name, signer_client_id
        returns an envelope definition
        """

        # Set the values for the fields in the template
        ##
        # Parent Name 1 is a template tab I am trying to reach
        #
        parent_1 = Text(
            document_id="1", page_number="1",
            font="helvetica", font_size="size14",
        )
        parent_1.tab_id ="Text 1"
        parent_1.tab_label ="Parent Name 1"
        parent_1.value = "Tim NORTON"

        # Add the tabs model (including the SignHere tab) to the signer.
        # The Tabs object wants arrays of the different field/tab types
        tabs = Tabs(
            text_tabs=[parent_1, sign_here1, sign_here2]
        )
        
        # create a signer recipient to sign the document, identified by name and email
        # We"re setting the parameters via the object creation
        signer = TemplateRole(  # The signer
            email=args["signer_email"], name=args["signer_name"],
            # Setting the client_user_id marks the signer as embedded
            client_user_id=signer_client_id,
            template_id="xxxx0b76-xxxx-xxxx-afc13a52xxxx",
            role_name="Parent",
            tabs=tabs
        )
                
        # create an envelope custom field to save our application"s
        # data about the envelope

        custom_field = TextCustomField(
            name="app metadata item",
            required="false",
            show="true",  # Yes, include in the CoC
            value="1234567"
        )

        cf = CustomFields(text_custom_fields=[custom_field])
        env.custom_fields = cf
        env.status = "sent"
        env.template_roles = [signer]
        env.email_subject = "Please sign this release sent from your school for a Laptop"
        

        # Add the tabs model (including the sign_here tabs) to the signer
        # The Tabs object wants arrays of the different field/tab types
        signer1.tabs = Tabs(sign_here_tabs=[sign_here1, sign_here2], text_tabs=[parent_1])

        # Add the recipients to the envelope object
        recipients = Recipients(signers=[signer1])
        env.recipients = recipients
   

        return env

I am having trouble finding the API documentation so that is not helping me.

  1. load the template I want
  2. fill in the field/tags I want
  3. send the envelope and have the document show the fields/tags filled in with the data I want
  4. I cannot find away to associate the field to the template field. I am frustrated...

I use jwt_console and eg002 and eg013 combined to get something to work. The code above only sends the envelope but I cannot see how to fill in the fields already in the template.

1

There are 1 answers

1
Inbar Gazit On

eg017 is what you want for this, it does exactly what you need.

https://github.com/docusign/code-examples-python/blob/master/app/eSignature/examples/eg017_set_template_tab_values.py

The issue you probably have has to do with the fields being defined in two places and not being in synch.

If you define the fields on the template, you cannot expect them to have the values if you add them to the envelope separately and vice versa.

What you need to do to fix this is either:

  1. Not use composite template and see the example above which uses templates till, and fills tabs, but not using composite.

  2. If you still want to use composite templates, you need to merge the recipient and their fields from the two templates you're using.

enter image description here