2017-01-20 56 views
0

我有一個Winforms vb.net應用程序,它發送pdf到docusign進行簽名。這是我的問題。Docusign標籤僅在使用多個文檔時丟失

場景#1:PDF#1單獨發送和所有選項卡顯示爲預期

方案#2:PDF#2單獨發送和所有選項卡顯示爲預期

場景#3:PDF#1 & pdf#2一起發送,pdf#1中缺少6個選項卡中的4個。缺少的選項卡是初始,日期簽名和日期。簽名& FullName按預期顯示pdf#1。所有選項卡也可以正確顯示pdf#2。

我用非常獨特AnchorStrings失蹤的標籤。但簽名& FullName AnchorStrings對於這兩個文檔都是相同的。

我還識別所述DocumentId,RecipientId和每的PageNumber API參考根據需要。

我來的結論,我們將擁有的對每個文檔發送拼命。

'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": "[email protected]", 
      "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!" 
    }' 
+0

您可以請分享您的請求正文和您正在使用的API。 –

+0

Praveen我正在使用引用dll的NuGet包版本2.0.6,而不是Rest或Soap API。所以我沒有看到讓你獲得請求正文的方法。 – Chris

+0

你可以分享你的VB.NET代碼嗎? –

回答

2

是,每個文件都有自己的ID,獨特的信封。每個錨(自動播放)選項卡都需要包含一個documentId,用於指定該選項卡所屬的文檔。

如果你有兩個文件,各得到一個SignHere選項卡,然後你需要兩個不同的SignHere標籤的定義,每一個文件。這兩個選項卡使用相同的錨字符串文本並不重要。

+0

謝謝Larry,那就是我的設置。出於某種原因存在衝突並且不能正確渲染。 – Chris

+0

@克里斯 - 對不起,你有這個麻煩。請編輯您的問題(使用它下面的編輯鏈接)將您的請求主體添加到您的問題。您可以使用API​​記錄器查看您的請求。請參閱https://www.docusign。com/blog/dsdev-signature-api-logging-made-easy/ –

+0

Larry,我設置Logger並在POST上得到錯誤狀態。 「問題:無法獲取文件」即使這些文件似乎正在工作。 – Chris

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]) 
+0

很高興你解決了它!感謝您使用DocuSign –

+0

拉里只是讓你知道,我很難讓API Logger工作。我曾多次認證,但幾乎不會顯示我需要的數據。我只有10次左右纔得到真實的數據。它通常會向我顯示除請求之外的很多其他日誌,或者根本不顯示任何內容。不知道爲什麼。 – Chris

+0

嗨@Chris謝謝你的報告。記錄器捕獲您帳戶的所有活動。當你想要的只是你的應用程序的所有活動時,這可能是一個問題。當我們努力改進記錄器時,我會進一步研究這一點。 –