Docusign 模板:有一个模板我想使用 python 来填写一些模板字段/选项卡。我如何访问选项卡来填写它们

问题描述 投票:0回答:1

我希望能够填写模板选项卡,但无论我尝试什么,我都找不到如何做到这一点。 我查看了 git hub 中的示例代码以及我能找到的 DocuServ 的每一个 API 字典。 我希望能够填写我放置在模板中的文本字段。他们都有不同的 id。 我尝试编辑他们的开始示例但无济于事。

这是我正在尝试的代码。至少这会给我我想要的模板。

    @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

我无法找到 API 文档,因此这对我没有帮助。

  1. 加载我想要的模板
  2. 填写我想要的字段/标签
  3. 发送信封并让文档显示填写了我想要的数据的字段/标签
  4. 我无法找到将该字段关联到模板字段的方法。 我很沮丧...

我结合使用 jwt_console 和eg002 和eg013 来让一些东西发挥作用。 上面的代码仅发送信封,但我看不到如何填写模板中已有的字段。

python-3.x docusignapi templatetags docusign-sdk
1个回答
0
投票

eg017 就是您想要的,它正是您所需要的。

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

您可能遇到的问题与在两个地方定义的字段并且不同步有关。

如果您在模板上定义了字段,则如果您将它们单独添加到信封中,则不能期望它们具有值,反之亦然。

要解决此问题,您需要做的是:

  1. 不使用复合模板,请参阅上面的示例,该示例使用模板直到并填充选项卡,但不使用复合模板。

  2. 如果您仍想使用复合模板,您需要合并您正在使用的两个模板中的收件人及其字段。

© www.soinside.com 2019 - 2024. All rights reserved.