Generate File

🗂️ Generate any file and attach to field or another function.

You can generate any file with this function and store it in s3. You need to send the following parameter inside the function:

  • filename: The name of the file to be generated.
  • extension: The file extension. For example, xml.
  • contentType: The content type of the file. For example, application/xml.
  • content: The actual content of the file.

The example below shows how you generate the file and then attach it to a file field or a sendEmail function.

async function script(C) {
    const entryDetails = {
        entryId: C.getEvent().entryId,
        recordInternalId: C.getEvent().recordInternalId,
    };

    const xmlString = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
  <element1>value1</element1>
  <element2>value2</element2>
  <nestedElement>
    <subElement>subValue</subElement>
  </nestedElement>
</root>`;

    const fileResponse = await C.generateFile({
        filename: "test12",
        extension: "xml",
        contentType: "application/xml",
        content: xmlString,
    }); // file response is of type attachment.

    // You can directly pass fileResponse to a file field
    const updateResponse = await C.updateEntries({
        updates: [
            {
                value: {
                    attachments: [fileResponse],
                },
                valuesType: "iov",
                ...entryDetails,
            },
        ],
    });

    // INFO: To show a download button in the workflow UI, first attach the generated file to an entry and use C.downloadFiles
    await C.downloadFiles({
        name: "attachments",
        ...entryDetails,
        fieldIds: ["attachments"], // backlog-items has file bucket field called attachments
    });

    // You can directly sent it to sendEmail function
    const sendEmailResponse = await C.sendEmail({
        from: { email: "[email protected]", name: "Prabhat Pandey" },
        to: ["[email protected]"],
        subject: "Testing file attachemnt",
        body: "Hello, world.\n Check for attachments",
        attachments: [fileResponse],
        ...entryDetails,
    });

    return {
        fileResponse,
        updateResponse,
        sendEmailResponse,
    };
}

Output

This function returns an attachment. You can attach it to any file or file bucket type field. You can also send it directly in sendEmail function.

📌 Need Help?

If you require assistance or encounter any issues, please don't hesitate to contact us for further support.