Workflow: Create file and attach it to a resource


I am using the 2021.9 version and I have an issue with using the workflow step “Create file…”. I would like to generate a PDF file with a summary for my customer and allow my user to download it. I have gathered the data and used the “Render template” function. As the result of this function, I am getting the report (RenderedDocument) variable. As a next step, I am trying to use the “Create file…” function. Those are my input parameters:

  • content* (Reader) report.document (output variable from the “Render template”)
  • resource* (ComposeRecord) record (the workflow will be started on the record details page)

I am also defining a name for the output variable (attachment).

I am getting an error: “not allowed to create empty attachments”

  1. I have no idea why this error occurs (I have used prompted to verify the report.document variable is not empty)
  2. I am unable to locate any documentation regarding using the Attachment:
  • how to add it to the record?
  • do I need any special field within the record where any link to the attachment is held?
  • how do I access the attachment?

Any help will be as always appreciated :slight_smile:

I messed up the attachment handling code so we’ll need to do a workaround for now; apologies for this.

This is what you need to do (you can click on images to expand them; they’ll be a bit small in preview)

Render the document

This stays as is; just make sure that the parameters are ok; this is what I used:

Prepare a record

Use the compose record maker function to prepare a record (you can use record lookup or other functions that give access to a record).

Make sure that the record has a field of type File upload.

Create an attachment

The raw file needs to be converted to an attachment – Create a file and attach it to a resource function.

Here is where the issue lies – you can’t use the reader (internals expect a ReadSeeker, but the workflow passes in a Reader).

Instead of Reader select the String type. The result will be the same but it does need to do some extra pointless steps under the hood (the handler converts the provided Reader to a String and then back to a ReadSeeker.
There shouldn’t be much of a performance impact unless you’re working with giant documents.

Important make sure to provide the file extension with the file name – welcome_message.pdf from my example.

Reference the attachment to the record

Use an expression step to link the attachment to the record; this is how it is for me (my field is called document)

Screenshot from 2022-04-12 15-02-19

Create/update record

Use a compose record create function when creating new records, or compose record update function when updating existing records.

With this, my documents are being created.

1 Like

As always: thanks a lot. Works great :slight_smile:

1 Like

Perfect :ok_hand:
We also have a patch in place for the issue which should be available ~next week.

1 Like