Forum Discussion

rvalentine82's avatar
rvalentine82
Qrew Member
7 months ago

Document creation - Save PDF to field in record

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? 

6 Replies

  • 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
    ...

    • MarkStenberg2's avatar
      MarkStenberg2
      Qrew Trainee

      Does anyone have the above with actual data filled in as an example?  It's not readily apparent to someone without specific YAML experience what some of the references are to data that needs to be customized.  The "change me" slug, table id, field references I get.  It's mostly the action body I'm having trouble with.  Also, I need this just to save the pdf document from the template to a table, not the email section. Thanks.

    • Steven's avatar
      Steven
      Qrew Member

      Hi Rick,

      Can you give the full yaml file please? I try to import the yaml above but I got error. Thanks!!!

      • Rick_Shurtliff's avatar
        Rick_Shurtliff
        Qrew Member

        Hi Steven, what was the error?  Did you change the account slugs and info in the above where it says change me? 

  • 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

  • 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