please_work
please_work

Reputation: 13

DocuSign C# SDK setting prefilled fields

I am attempting to set pre-filled fields before sending an email but it doesn't seem to be working. I have two such text fields with Data Labels fee and otherFee.

fee

otherFee

When attempting to send, the program throws the following error: {"errorCode":"REQUIRED_TAB_INCOMPLETE","message":"A Required field is incomplete. TabId: 0dfdf411-cafa-441e-b6e4-ef617e12de92"} TabId here changes with each call. I know it must be associated with my pre-filled fields because when I remove them, or remove the Mandatory attribute, via the template tool on the website the email is sent without issue. Not sure why I am getting this unique identifier rather than the Data Label they are actually set to.

My code:

            //prepare client
            var apiClient = new ApiClient(basePath);
            apiClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
            var envelopesApi = new EnvelopesApi(apiClient);
            
            //Make the envelope
            TemplateRole signer1 = new TemplateRole
            {
                Email = signerEmail,
                Name =  signerName,
                RoleName = "merchant",
            };
            EnvelopeDefinition envelope = new EnvelopeDefinition
            {
                TemplateId = templateId,
                TemplateRoles = new List<TemplateRole> { signer1 },
                Status = "created"
            };
            EnvelopeSummary result = envelopesApi.CreateEnvelope(accountId, envelope);

            //set fields
            Text fee = new Text {TabLabel = "fee", Value = "$0.50"};
            Text otherFee = new Text {TabLabel = "otherFee", Value = "$1.77"};
            PrefillTabs prefillTabs = new PrefillTabs {TextTabs = new List<Text> {fee, otherFee}};
            Tabs tabs = new Tabs {PrefillTabs = prefillTabs};
            var res = envelopesApi.CreateDocumentTabs(accountId, result.EnvelopeId, "1", tabs);
            
            //update and send
            Envelope envInfo = new Envelope();
            envInfo.Status = "sent";
            envelopesApi.Update(accountId, result.EnvelopeId, envInfo);

Any help is greatly appreciated, this has been driving me crazy.

Upvotes: 1

Views: 1618

Answers (1)

Larry K
Larry K

Reputation: 49104

You can use prefill tabs, here is a live example.

Your problem is that you're trying to set the pre-fill tabs for a template. That is not supported. Instead, use regular tabs and mark them as read only. The API Request Builder has many template code examples you can try live.

As noted above, you cannot set prefill tabs for documents that are in a server template. See the templates post

Prefill tabs are more meant for humans using the DocuSign web app to send the envelope (transaction). Your API integration app can use regular tabs in read-only mode.

Here are JSON and C# examples for prefill tabs from the API Request Builder.

  "envelopeDefinition": {
    "emailSubject": "Please sign the attached document",
    "status": "sent",
    "documents": [
      {
        "filename": "anchorfields.pdf",
        "name": "Example document",
        "fileExtension": "pdf",
        "documentId": "1",
        "tabs": {
          "prefillTabs": {
            "textTabs": [
              {
                "anchorString": "/field1/ ",
                "bold": "true",
                "font": "Garamond",
                "fontColor": "BrightBlue",
                "fontSize": "Size14",
                "value": "This field and the following are all \"prefill\" fields: "
              },
              {
                "anchorString": "/field1/ ",
                "anchorXOffset": "0",
                "anchorYOffset": "30",
                "bold": "true",
                "font": "Garamond",
                "fontColor": "Black",
                "fontSize": "Size12",
                "value": "Checkbox:"
              },
              {
                "anchorString": "/field1/ ",
                "anchorXOffset": "90",
                "anchorYOffset": "30",
                "bold": "true",
                "font": "Garamond",
                "fontColor": "Black",
                "fontSize": "Size12",
                "value": "Radio button:"
              },
              {
                "anchorString": "/field1/ ",
                "anchorXOffset": "0",
                "anchorYOffset": "60",
                "bold": "true",
                "font": "Garamond",
                "fontColor": "Black",
                "fontSize": "Size12",
                "value": "Sender name:"
              },
              {
                "anchorString": "/field1/ ",
                "anchorXOffset": "190",
                "anchorYOffset": "60",
                "bold": "true",
                "font": "Garamond",
                "fontColor": "Black",
                "fontSize": "Size12",
                "value": "Sender company:"
              }
            ],
            "checkboxTabs": [
              {
                "anchorString": "/field1/ ",
                "anchorXOffset": "70",
                "anchorYOffset": "30",
                "fontSize": "Size14",
                "selected": "true"
              }
            ],
            "radioGroupTabs": [
              {
                "radios": [
                  {
                    "anchorString": "/field1/",
                    "anchorXOffset": "185",
                    "anchorYOffset": "30",
                    "selected": "true",
                    "fontSize": "Size14"
                  }
                ]
              }
            ],
            "senderNameTabs": [
              {
                "anchorString": "/field1/ ",
                "anchorXOffset": "90",
                "anchorYOffset": "58",
                "font": "Garamond",
                "fontColor": "DarkGreen",
                "fontSize": "Size12"
              }
            ],
            "senderCompanyTabs": [
              {
                "anchorString": "/field1/ ",
                "anchorXOffset": "310",
                "anchorYOffset": "58",
                "font": "Garamond",
                "fontColor": "DarkGreen",
                "fontSize": "Size12"
              }
            ]
          }
        }
      }
    ],
    "recipients": {
      "signers": [
        {
          "email": "[email protected]",
          "name": "Signer's name",
          "recipientId": "1",
          "clientUserId": "1000",
          "tabs": {
            "signHereTabs": [
              {
                "anchorString": "/sig1/",
                "anchorXOffset": "20",
                "anchorUnits": "pixels"
              }
            ]
          }
        }
      ]
    }
  }

C#

        static string SendDocuSignEnvelope()
        {
            SignHere signHereTab1 = new SignHere
            {
                AnchorString = "/sig1/",  
                AnchorUnits = "pixels",  
                AnchorXOffset = "20" 
            };
            List<SignHere> signHereTabs1 = new List<SignHere> {signHereTab1};
            Tabs tabs1 = new Tabs
            {
                SignHereTabs = signHereTabs1 
            };
            Signer signer1 = new Signer
            {
                ClientUserId = "1000",  
                Email = "[email protected]",  
                Name = "Signer's name",  
                RecipientId = "1",  
                Tabs = tabs1 
            };
            List<Signer> signers1 = new List<Signer> {signer1};
            Recipients recipients1 = new Recipients
            {
                Signers = signers1 
            };
            Text textTab1 = new Text
            {
                AnchorString = "/field1/ ",  
                Bold = "true",  
                Font = "Garamond",  
                FontColor = "BrightBlue",  
                FontSize = "Size14",  
                Value = "This field and the following are all ""prefill"" fields: " 
            };
            Text textTab2 = new Text
            {
                AnchorString = "/field1/ ",  
                AnchorXOffset = "0",  
                AnchorYOffset = "30",  
                Bold = "true",  
                Font = "Garamond",  
                FontColor = "Black",  
                FontSize = "Size12",  
                Value = "Checkbox:" 
            };
            Text textTab3 = new Text
            {
                AnchorString = "/field1/ ",  
                AnchorXOffset = "90",  
                AnchorYOffset = "30",  
                Bold = "true",  
                Font = "Garamond",  
                FontColor = "Black",  
                FontSize = "Size12",  
                Value = "Radio button:" 
            };
            Text textTab4 = new Text
            {
                AnchorString = "/field1/ ",  
                AnchorXOffset = "0",  
                AnchorYOffset = "60",  
                Bold = "true",  
                Font = "Garamond",  
                FontColor = "Black",  
                FontSize = "Size12",  
                Value = "Sender name:" 
            };
            Text textTab5 = new Text
            {
                AnchorString = "/field1/ ",  
                AnchorXOffset = "190",  
                AnchorYOffset = "60",  
                Bold = "true",  
                Font = "Garamond",  
                FontColor = "Black",  
                FontSize = "Size12",  
                Value = "Sender company:" 
            };
            List<Text> textTabs1 = new List<Text> {textTab1, textTab2, textTab3, textTab4, textTab5};
            Checkbox checkboxTab1 = new Checkbox
            {
                AnchorString = "/field1/ ",  
                AnchorXOffset = "70",  
                AnchorYOffset = "30",  
                FontSize = "Size14",  
                Selected = "true" 
            };
            List<Checkbox> checkboxTabs1 = new List<Checkbox> {checkboxTab1};
            Radio radio1 = new Radio
            {
                AnchorString = "/field1/",  
                AnchorXOffset = "185",  
                AnchorYOffset = "30",  
                FontSize = "Size14",  
                Selected = "true" 
            };
            List<Radio> radios1 = new List<Radio> {radio1};
            RadioGroup radioGroupTab1 = new RadioGroup
            {
                Radios = radios1 
            };
            List<RadioGroup> radioGroupTabs1 = new List<RadioGroup> {radioGroupTab1};
            SenderName senderNameTab1 = new SenderName
            {
                AnchorString = "/field1/ ",  
                AnchorXOffset = "90",  
                AnchorYOffset = "58",  
                Font = "Garamond",  
                FontColor = "DarkGreen",  
                FontSize = "Size12" 
            };
            List<SenderName> senderNameTabs1 = new List<SenderName> {senderNameTab1};
            SenderCompany senderCompanyTab1 = new SenderCompany
            {
                AnchorString = "/field1/ ",  
                AnchorXOffset = "310",  
                AnchorYOffset = "58",  
                Font = "Garamond",  
                FontColor = "DarkGreen",  
                FontSize = "Size12" 
            };
            List<SenderCompany> senderCompanyTabs1 = new List<SenderCompany> {senderCompanyTab1};
            PrefillTabs prefillTabs1 = new PrefillTabs
            {
                CheckboxTabs = checkboxTabs1,  
                RadioGroupTabs = radioGroupTabs1,  
                SenderCompanyTabs = senderCompanyTabs1,  
                SenderNameTabs = senderNameTabs1,  
                TextTabs = textTabs1 
            };
            Tabs tabs2 = new Tabs
            {
                PrefillTabs = prefillTabs1 
            };
            Document document1 = new Document
            {
                DocumentId = "1",  
                FileExtension = "pdf",  
                DocumentBase64 = ReadContent("anchorfields.pdf"),  // filename is anchorfields.pdf
                Name = "Example document",  
                Tabs = tabs2 
            };
            List<Document> documents1 = new List<Document> {document1};
            EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition
            {
                Documents = documents1,  
                EmailSubject = "Please sign the attached document",  
                Recipients = recipients1,  
                Status = "sent" 
            };

            ApiClient apiClient = new ApiClient(basePath);
            apiClient.Configuration.AddDefaultHeader("Authorization", "Bearer " + accessToken);
            EnvelopesApi envelopesApi = new EnvelopesApi(apiClient);
            try
            {
                EnvelopeSummary results = envelopesApi.CreateEnvelope(accountId, envelopeDefinition);
                Console.WriteLine($"Envelope status: {results.Status}. Envelope ID: {results.EnvelopeId}");
                return results.EnvelopeId;
            }
            catch (ApiException e)
            {
                Console.WriteLine("Exception while creating envelope!");
                Console.WriteLine($"Code: {e.ErrorCode}\nContent: {e.ErrorContent}");
                //Console.WriteLine(e.Message);
                return "";
            }
        }

 

Upvotes: 3

Related Questions