Docusign Template:有一个模板我想用python来填写一些模板字段/标签,我如何访问标签来填写它们

23c0lvtd  于 2023-11-20  发布在  Python
关注(0)|答案(1)|浏览(153)

我希望能够填写模板选项卡,但无论我尝试什么,我都找不到如何做到这一点。我已经查看了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.加载我想要的模板
1.填写我想要的字段/标签
1.发送信封,并有文件显示的字段/标签填写的数据,我想
1.我无法找到将字段与模板字段关联的方法。我很沮丧.
我使用jwt_console和eg 002和eg 013组合来完成一些工作。上面的代码只发送信封,但我看不到如何填写模板中已经存在的字段。

9w11ddsr

9w11ddsr1#

eg017是你想要的,它确实是你需要的。
https://github.com/docusign/code-examples-python/blob/master/app/eSignature/examples/eg017_set_template_tab_values.py
这个问题可能与在两个地方定义的字段不同步有关。
如果在模板上定义字段,则不能期望它们在单独添加到信封时具有相应的值,反之亦然。
要解决这个问题,你需要做的是:
1.不使用复合模板,请参阅上面的示例,其中使用模板直到,并填充选项卡,但不使用复合。
1.如果您仍然想使用composite templates,则需要合并您正在使用的两个模板中的收件人及其字段。


的数据

相关问题