Docusign标签仅在使用多个文档时丢失

时间:2017-01-20 21:14:51

标签: vb.net winforms docusignapi

我有一个Winforms vb.net应用程序,它将pdf发送到docusign进行签名。这是我的问题。

场景#1:pdf#1单独发送,所有标签按预期显示

场景#2:pdf#2单独发送,所有标签按预期显示

场景#3:pdf#1& pdf#2一起发送,pdf#1中缺少6个选项卡中的4个。缺少的选项卡是Initial,DateSigned和Date。签名& FullName显示为pdf#1的预期。所有选项卡也正确显示pdf#2。

我正在为缺少的标签使用非常独特的AnchorStrings。但Signature& FullName AnchorStrings对于两个文档都是相同的。

我还根据API参考标识了DocumentId,RecipientId和PageNumber。

我得出的结论是,我们必须绝望地发送每份文件。

    'Public Sub SendForSignature(ByRef Docs As List(Of DocToSign), DocSigner As Signer)
        Try
            If Not UserHasLogin(User.Id) Then
                Throw New Exception("You do not have DocuSign credentials saved. Save your credentials in your User Settings to use DocuSign.")
            End If

            If Docs.Count = 0 Then
                Exit Try
            End If
            If String.IsNullOrWhiteSpace(DocSigner.Name) Then
                Throw New Exception("No recipient name found.")
            End If
            If String.IsNullOrWhiteSpace(DocSigner.Email) Then
                Throw New Exception("No recipient email address found.")
            End If

            If String.IsNullOrWhiteSpace(DocSigner.RecipientId) Then
                DocSigner.RecipientId = "1"
            End If
            If String.IsNullOrWhiteSpace(DocSigner.RoutingOrder) Then
                DocSigner.RoutingOrder = "1"
            End If

            'Create Envelope
            Dim envDef As New EnvelopeDefinition() With {
                .EmailSubject = $"Signature Requested from {User.FirstName}",
                .EmailBlurb = "Please sign the document. Thank you!"}
            envDef.Documents = New List(Of Document)()
            envDef.CustomFields = New CustomFields()
            envDef.Recipients = New Recipients()

            'Used for Documentid
            Dim i As Integer = 1

            For Each pdf As DocToSign In Docs

                If Not File.Exists(pdf.Path) Then
                    Throw New Exception($"PDF file was not found at '{pdf.Path}'.")
                End If
                If Not Path.GetExtension(pdf.Path).ToLower.EndsWith("pdf") Then
                    Throw New Exception("File path did not end with pdf, invalid file format.")
                End If

                Dim filebytes As Byte() = File.ReadAllBytes(pdf.Path)

                Dim lcf As New List(Of ListCustomField)
                lcf.Add(New ListCustomField With {.Name = "ReferenceGUID", .Value = pdf.ReferenceGUID, .Required = "true", .Show = "false"})
                lcf.Add(New ListCustomField With {.Name = "UserId", .Value = User.Id.ToString, .Required = "true", .Show = "false"})
                envDef.CustomFields.ListCustomFields = lcf

                'Add a document to the envelope 
                Dim doc As New Document()
                doc.DocumentBase64 = Convert.ToBase64String(filebytes)
                doc.Name = Path.GetFileName(pdf.Path)
                doc.DocumentId = i.ToString()
                doc.DocumentFields = New List(Of NameValue)
                doc.DocumentFields.Add(New NameValue With {.Name = "ReferenceGUID", .Value = pdf.ReferenceGUID})
                doc.ApplyAnchorTabs = "true"
                envDef.Documents.Add(doc)

                'Move Tabs per Document
                Select Case pdf.DocumentTypeId
                    Case 2 'Client Lease
                        'Change for Master Leases
                        If pdf.IsSubLease Then

                        Else
                            SetupClientLease(DocSigner, i.ToString)
                        End If

                    Case 18 'Client NTV
                        SetupClientNTV(DocSigner, i.ToString)

                    Case 7 'Addendum
                        SetupClientAddendum(DocSigner, i.ToString)

                    Case 6 'SOP
                        SetupClientSOP(DocSigner, i.ToString)

                    Case 41 'Master Rental Agreement
                        Dim ECHSigner As New Signer With {.Name = User.FullName, .Email = User.EmailAddress, .RecipientId = "2", .RoutingOrder = "1"}
                        DocSigner.RoutingOrder = "2"
                        envDef.Recipients.Signers.Add(ECHSigner)
                        SetupMasterRentalAgreement(DocSigner, ECHSigner, i.ToString)

                End Select

                'Set next doc id
                i += 1
            Next

            'Add a recipient to sign the documeent
            envDef.Recipients.Signers = New List(Of Signer)()
            envDef.Recipients.Signers.Add(DocSigner)

            'Set envelope status to "sent" to immediately send the signature request 
            envDef.Status = "sent"

            'Use the EnvelopesApi to send the signature request! 
            Dim envelopesApi As New EnvelopesApi()
            Dim envelopeSummary As EnvelopeSummary = envelopesApi.CreateEnvelope(accountid, envDef)

        Catch ex As Exception
            Throw New Exception(ex.Message, ex.InnerException)
        End Try
    End Sub

    Private Sub SetupClientNTV(ByRef signer As Signer, DocId As String)
        Try
            ' Create a |SignHere| tab somewhere on the document for the recipient to sign 
            signer.Tabs = New Tabs()
            signer.Tabs.SignHereTabs = New List(Of SignHere)
            signer.Tabs.InitialHereTabs = New List(Of InitialHere)
            signer.Tabs.DateTabs = New List(Of [Date])
            signer.Tabs.FullNameTabs = New List(Of FullName)
            signer.Tabs.DateSignedTabs = New List(Of DateSigned)

            'Signature Tab
            Dim signHere As New SignHere() With {
                .AnchorString = "Guest Signature",
                .AnchorXOffset = "2",
                .AnchorYOffset = "-12",
                .DocumentId = DocId,
                .RecipientId = "1",
                .AnchorMatchWholeWord = "true",
                .AnchorCaseSensitive = "true",
                .AnchorIgnoreIfNotPresent = "true",
                .PageNumber = "1"}

            'Full Name Tab
            Dim fullName As New FullName With {
                .AnchorString = "Guest Printed Name",
                .AnchorXOffset = "0",
                .AnchorYOffset = "-12",
                .DocumentId = DocId,
                .AnchorMatchWholeWord = "true",
                .AnchorCaseSensitive = "true",
                .AnchorIgnoreIfNotPresent = "true",
                .PageNumber = "1"}

            'Date Signed Tabs
            Dim dateSigned As New DateSigned() With {
                .AnchorString = "Date Signed",
                .AnchorXOffset = "0",
                .AnchorYOffset = "-12",
                .DocumentId = DocId,
                .AnchorMatchWholeWord = "true",
                .AnchorCaseSensitive = "true",
                .AnchorIgnoreIfNotPresent = "true",
                .PageNumber = "1"}

            'Date Tabs
            Dim ntvdate As New [Date] With {
                .AnchorString = "Initial ONLY ONE",
                .AnchorXOffset = "292",
                .AnchorYOffset = "26",
                .DocumentId = DocId,
                .AnchorMatchWholeWord = "true",
                .AnchorCaseSensitive = "true",
                .AnchorIgnoreIfNotPresent = "true",
                .PageNumber = "1",
                .ConditionalParentLabel = "initial1",
                .ConditionalParentValue = "on",
                .Width = 100}

            'Initial Tabs
            Dim initial1 As New InitialHere With {
                .AnchorString = "Initial ONLY ONE",
                .AnchorXOffset = "2",
                .AnchorYOffset = "41",
                .DocumentId = DocId,
                .AnchorMatchWholeWord = "true",
                .AnchorCaseSensitive = "true",
                .AnchorIgnoreIfNotPresent = "true",
                .PageNumber = "1",
                .Optional = "true",
                .TabLabel = "initial1",
                .ScaleValue = "0.75"} 'Scale value is size - 1.0 is full size, 0.5 is 50% size

            Dim initial2 As New InitialHere With {
                .AnchorString = "Initial ONLY ONE",
                .AnchorXOffset = "2",
                .AnchorYOffset = "82",
                .DocumentId = DocId,
                .AnchorMatchWholeWord = "true",
                .AnchorCaseSensitive = "true",
                .AnchorIgnoreIfNotPresent = "true",
                .PageNumber = "1",
                .Optional = "true",
                .TabLabel = "initail2",
                .ScaleValue = "0.75"}


            signer.Tabs.SignHereTabs.Add(signHere)
            signer.Tabs.DateTabs.Add(ntvdate)
            signer.Tabs.FullNameTabs.Add(fullName)
            signer.Tabs.DateSignedTabs.Add(dateSigned)
            signer.Tabs.InitialHereTabs.Add(initial1)
            signer.Tabs.InitialHereTabs.Add(initial2)
        Catch ex As Exception
            Throw New Exception(ex.Message, ex.InnerException)
        End Try
    End Sub

    Private Sub SetupClientSOP(ByRef signer As Signer, DocId As String)
        Try
            ' Create a |SignHere| tab somewhere on the document for the recipient to sign 
            signer.Tabs = New Tabs()
            signer.Tabs.SignHereTabs = New List(Of SignHere)
            signer.Tabs.TextTabs = New List(Of Text)
            signer.Tabs.FullNameTabs = New List(Of FullName)
            signer.Tabs.DateSignedTabs = New List(Of DateSigned)
            signer.Tabs.RadioGroupTabs = New List(Of RadioGroup)

            Dim rg As New RadioGroup With {
                .DocumentId = DocId,
                .GroupName = "radios",
                .RecipientId = "1",
                .Radios = New List(Of Radio)}


            'Signature Tab
            Dim signHere As New SignHere() With {
                .AnchorString = "Guest Signature",
                .AnchorXOffset = "3",
                .AnchorYOffset = "-11",
                .DocumentId = DocId,
                .AnchorMatchWholeWord = "true",
                .AnchorCaseSensitive = "true",
                .AnchorIgnoreIfNotPresent = "true",
                .PageNumber = "1"}

            'Radio Tabs
            Dim radio1 As New Radio With {
                .AnchorString = "Credit Card on File",
                .AnchorXOffset = "-27",
                .AnchorYOffset = "-3",
                .AnchorMatchWholeWord = "true",
                .AnchorCaseSensitive = "true",
                .AnchorIgnoreIfNotPresent = "true",
                .Required = "true",
                .Selected = "true",
                .PageNumber = "1"}

            Dim radio2 As New Radio With {
                .AnchorString = "Auto Debit my",
                .AnchorXOffset = "-27",
                .AnchorYOffset = "-3",
                .AnchorMatchWholeWord = "true",
                .AnchorCaseSensitive = "true",
                .AnchorIgnoreIfNotPresent = "true",
                .Required = "true",
                .Selected = "false",
                .PageNumber = "1"}

            Dim radio3 As New Radio With {
                .AnchorString = "Postal Mail (",
                .AnchorXOffset = "-27",
                .AnchorYOffset = "-3",
                .AnchorMatchWholeWord = "true",
                .AnchorCaseSensitive = "true",
                .AnchorIgnoreIfNotPresent = "true",
                .Required = "true",
                .Selected = "false",
                .PageNumber = "1"}

            Dim radio4 As New Radio With {
                .AnchorString = "Wire Transfer",
                .AnchorXOffset = "-27",
                .AnchorYOffset = "-3",
                .AnchorMatchWholeWord = "true",
                .AnchorCaseSensitive = "true",
                .AnchorIgnoreIfNotPresent = "true",
                .Required = "true",
                .Selected = "false",
                .PageNumber = "1"}


            'Text Tabs (For email address - Using EmailAddress is not optional)
            Dim emailHere As New Text With {
                .AnchorString = "Email address where invoices should be sent:",
                .AnchorXOffset = "160",
                .AnchorYOffset = "-3",
                .DocumentId = DocId,
                .AnchorMatchWholeWord = "true",
                .AnchorCaseSensitive = "true",
                .Required = "false",
                .PageNumber = "1",
                .Width = 225}

            'Full Name Tab
            Dim fullName As New FullName With {
                .AnchorString = "Guest Printed Name",
                .AnchorXOffset = "0",
                .AnchorYOffset = "-11",
                .DocumentId = DocId,
                .AnchorMatchWholeWord = "true",
                .AnchorCaseSensitive = "true",
                .AnchorIgnoreIfNotPresent = "true",
                .PageNumber = "1"}

            'Date Tab
            Dim dateHere As New DateSigned() With {
                .AnchorString = "Date:",
                .AnchorXOffset = "20",
                .AnchorYOffset = "-3",
                .DocumentId = DocId,
                .AnchorMatchWholeWord = "true",
                .AnchorCaseSensitive = "true",
                .PageNumber = "1"}


            rg.Radios.Add(radio1)
            rg.Radios.Add(radio2)
            rg.Radios.Add(radio3)
            rg.Radios.Add(radio4)
            signer.Tabs.SignHereTabs.Add(signHere)
            signer.Tabs.RadioGroupTabs.Add(rg)
            signer.Tabs.TextTabs.Add(emailHere)
            signer.Tabs.FullNameTabs.Add(fullName)
            signer.Tabs.DateSignedTabs.Add(dateHere)
        Catch ex As Exception
            Throw New Exception(ex.Message, ex.InnerException)
        End Try
    End Sub`

请求正文

'{
"documents": [
    {
        "documentId": "1",
        "name": "2teevgqk2dm.pdf",
        "documentFields": [
            {
                "name": "ReferenceGUID",
                "value": "2582db83-cf6e-4611-9daf-321f40a7440a"
            }
        ],
        "documentBase64": "[Base64 data omitted]",
        "applyAnchorTabs": "true"
    },
    {
        "documentId": "2",
        "name": "dwwkrtmjwk3.pdf",
        "documentFields": [
            {
                "name": "ReferenceGUID",
                "value": "2582db83-cf6e-4611-9daf-321f40a7440a"
            }
        ],
        "documentBase64": "[Base64 data omitted]",
        "applyAnchorTabs": "true"
    }
],
"recipients": {
    "signers": [
        {
            "tabs": {
                "signHereTabs": [
                    {
                        "documentId": "2",
                        "pageNumber": "1",
                        "anchorString": "Guest Signature",
                        "anchorXOffset": "3",
                        "anchorYOffset": "-11",
                        "anchorIgnoreIfNotPresent": "true",
                        "anchorCaseSensitive": "true",
                        "anchorMatchWholeWord": "true"
                    }
                ],
                "fullNameTabs": [
                    {
                        "documentId": "2",
                        "pageNumber": "1",
                        "anchorString": "Guest Printed Name",
                        "anchorXOffset": "0",
                        "anchorYOffset": "-11",
                        "anchorIgnoreIfNotPresent": "true",
                        "anchorCaseSensitive": "true",
                        "anchorMatchWholeWord": "true"
                    }
                ],
                "dateSignedTabs": [
                    {
                        "documentId": "2",
                        "pageNumber": "1",
                        "anchorString": "Date:",
                        "anchorXOffset": "20",
                        "anchorYOffset": "-3",
                        "anchorCaseSensitive": "true",
                        "anchorMatchWholeWord": "true"
                    }
                ],
                "textTabs": [
                    {
                        "width": 225,
                        "required": "false",
                        "documentId": "2",
                        "pageNumber": "1",
                        "anchorString": "Email address where invoices should be sent:",
                        "anchorXOffset": "160",
                        "anchorYOffset": "-3",
                        "anchorCaseSensitive": "true",
                        "anchorMatchWholeWord": "true"
                    }
                ],
                "radioGroupTabs": [
                    {
                        "documentId": "2",
                        "recipientId": "1",
                        "groupName": "radios",
                        "radios": [
                            {
                                "pageNumber": "1",
                                "anchorString": "Credit Card on File",
                                "anchorXOffset": "-27",
                                "anchorYOffset": "-3",
                                "anchorIgnoreIfNotPresent": "true",
                                "anchorCaseSensitive": "true",
                                "anchorMatchWholeWord": "true",
                                "selected": "true",
                                "required": "true"
                            },
                            {
                                "pageNumber": "1",
                                "anchorString": "Auto Debit my",
                                "anchorXOffset": "-27",
                                "anchorYOffset": "-3",
                                "anchorIgnoreIfNotPresent": "true",
                                "anchorCaseSensitive": "true",
                                "anchorMatchWholeWord": "true",
                                "selected": "false",
                                "required": "true"
                            },
                            {
                                "pageNumber": "1",
                                "anchorString": "Postal Mail (",
                                "anchorXOffset": "-27",
                                "anchorYOffset": "-3",
                                "anchorIgnoreIfNotPresent": "true",
                                "anchorCaseSensitive": "true",
                                "anchorMatchWholeWord": "true",
                                "selected": "false",
                                "required": "true"
                            },
                            {
                                "pageNumber": "1",
                                "anchorString": "Wire Transfer",
                                "anchorXOffset": "-27",
                                "anchorYOffset": "-3",
                                "anchorIgnoreIfNotPresent": "true",
                                "anchorCaseSensitive": "true",
                                "anchorMatchWholeWord": "true",
                                "selected": "false",
                                "required": "true"
                            }
                        ]
                    }
                ]
            },
            "name": "Joe Blow",
            "email": "test@test.com",
            "recipientId": "1",
            "routingOrder": "1"
        }
    ]
},
"customFields": {
    "listCustomFields": [
        {
            "name": "ReferenceGUID",
            "show": "false",
            "required": "true",
            "value": "2582db83-cf6e-4611-9daf-321f40a7440a"
        },
        {
            "name": "UserId",
            "show": "false",
            "required": "true",
            "value": "14"
        }
    ]
},
"status": "sent",
"emailSubject": "Signature Requested",
"emailBlurb": "Please sign the document. Thank you!"
    }'

2 个答案:

答案 0 :(得分:2)

是的,每个文档都有自己的id,对于信封是唯一的。每个锚点(autoplace)选项卡都需要包含一个documentId,用于指定选项卡所属的文档。

如果您有两个文档并且每个文档都有一个SignHere选项卡,那么您需要两个不同的SignHere选项卡定义,每个文档一个。两个选项卡使用相同的锚字符串文本无关紧要。

答案 1 :(得分:0)

问题似乎是我创建了多个标签列表,而不是每个标签类型只有一个列表。所以只有第一个列表才有效。

在我循环设置每个文档的标签之前,我必须添加以下代码。

            DocSigner.Tabs = New Tabs()
            DocSigner.Tabs.SignHereTabs = New List(Of SignHere)
            DocSigner.Tabs.InitialHereTabs = New List(Of InitialHere)
            DocSigner.Tabs.TextTabs = New List(Of Text)
            DocSigner.Tabs.FullNameTabs = New List(Of FullName)
            DocSigner.Tabs.DateSignedTabs = New List(Of DateSigned)
            DocSigner.Tabs.RadioGroupTabs = New List(Of RadioGroup)
            DocSigner.Tabs.TitleTabs = New List(Of Title)
            DocSigner.Tabs.DateTabs = New List(Of [Date])