Skip to main content
Question

Document creation - Save PDF to field in record

  • October 3, 2024
  • 0 replies
  • 1409 views

Forum|alt.badge.img

Loving the new Document creation feature, but now I want to expand upon it and save the generated PDF to a file attachment field on the form. The feature just makes an API call and the PDF is returned in the response, so we should be able to build a Pipeline to iterate through the JSON response and save the PDF. I've been trying to set this up for a few days, but to no avail.

Has anyone done this yet? 

Forum|alt.badge.img+3

Yes, I'll give you the info but I can't take the credit.  Taylor Hardy at Quickbase did the work. In this case, we use it to send to Outlook, but you can change it to a file attachment field.

 Here is the yaml:


# Doc Gen Testing
#

# Account slugs:
#  - quickbase[CHANGE ME]: Realm Default Account <None>
#  - microsoft-outlook[CHANGE ME]:
#    <None>
---
- META:
    name: Doc Gen Testing
- ACTION quickbase[CHANGE ME] quickbase_api make -> a:
    inputs:
      method: GET
      url: https://api.quickbase.com/v1/docTemplates/1/generate?tableId=DBID_CHANGE_ME&format=pdf&pageSize=Letter&filename=Invoice&margin=1
        1 1 1&unit=in&orientation=portrait&recordId=1
    name: Generate Doc
- ACTION quickbase[CHANGE ME] quickbase_api make -> b:
    inputs:
      body: "{\n    \"to\": \"CHANGE_ME_TABLE_ID\",\n    \"data\": [\n      {\n        \"6\"\
        : {\n            \"value\": {\n                \"fileName\": \"{{a.json.fileName}}\"\
        ,\n                \"data\": \"{{a.json.data}}\"\n              }\n      \
        \  }\n      }\n    ],\n    \"fieldsToReturn\": []\n  }\n      }\n    }\n \
        \ ]\n}\n    \"fieldsToReturn\": []\n  }"
      method: POST
      url: https://api.quickbase.com/v1/records
    name: Save File to a Table
    note: 'Write the record '
- LOOKUP quickbase[CHANGE_ME] record look_up -> c:
    inputs-meta:
      table: '"Demo App: Invoice Files" <CHANGE_ME>'
      export_fields: '"File" <6>'
    inputs:
      id: '{{b.json.metadata.createdRecordIds[0]}}'
- ACTION microsoft-outlook[CHANGE_ME] email send_email_attachment -> d:
    inputs-meta:
      attachments:
        name: '{{c.file.file_name}}'
        url: '{{c.file.file_transfer_handle}}'
    inputs:
      body: Testing writing doc to QB table, looking up that record to get the file
        transfer handle, then emailing it using the outlook channel
      subject: Doc Gen Testing
      to_addresses: CHANGE_ME
...


KeithJusas
Forum|alt.badge.img+7

If you are looking to save the generated document in a file attachment field when using the new Document Creation functionality and the yaml code scares you...we got you! 

You can use our Exact Forms Plus add-on with the new Quickbase Document Templates to create your document and store it directly in a file attachment field...
For NO additional costs.

You don't have to be an existing Exact Forms Plus client either!

We'll be hosting a webinar after next week's EmpowerPro event...keep an eye out for the registration link.

Interested? Contact support@juicedtech.com for more info!

Keith


Forum|alt.badge.img+1

Hey Rick, 

 

Hopefully you can help me. I keep getting an error on the post request. "This field contains invalid jinja references".

 

These are my references in my post request. Similar to what you posted earlier. I just can't sort out what the problem is. Is it reference directly from the url of get request or does something need to be in the body?

 

"28": {

 

"value": {

 

"fileName": "{{b.json.fileName}}",

 

"data": "{{b.json.data}}"

}

}

 

Here is my get request url.

 

https://api.quickbase.com/v1/docTemplates/1/generate?tableId=table ID&recordId={{a.id}}&filename=Major Offense Log - {{a.date|date_mdy}}&format=docx&margin=1 1 1 1&unit=in&pageSize=Letter&orientation=portrait&realm=info