How to Download a Zoho Writer Merged Document to Your Local System from Zoho Creator

How to Download a Zoho Writer Merged Document to Your Local System from Zoho Creator

Introduction

What you'll learn: How to merge Zoho Creator data into a Zoho Writer template, store the generated document back in Creator, and trigger an automatic download to the user's local machine — all with a single button click.

Document automation is one of the most impactful ways to save time in any Zoho-powered business. If your team repeatedly creates reports, certificates, agreements, or letters from structured data, the manual copy-paste routine is both error-prone and slow. In this tutorial, we will walk through a clean, production-ready solution that connects Zoho Creator and Zoho Writer to generate and download merged documents automatically.

The Use Case

Imagine you manage a Plant database in Zoho Creator. Each record contains details like Plant Name and Organisation Name. You want users to click a button on a Plant Report, which then:

  • Pulls that plant's data from the Creator form
  • Merges it into a pre-built Zoho Writer template
  • Saves the generated document back into the Creator record
  • Triggers an instant download to the user's machine

No manual exports. No email attachments. Just one click.

How the Process Works

1Data is selected from the Zoho Creator Plant record
2The Zoho Writer template is merged with that data
3A merged document file is generated by Writer
4The file is uploaded to a File Upload field in Creator
5A public download link is constructed using the Perma Link
6The file is downloaded directly to the user's local system

Step-by-Step Implementation

Step 1Add a Form to Your Creator Application

Open your Zoho Creator application and Create a Plant Form. Add a Plant Name, Organisation Name,File Upload field in which file upload field will store the merged document and serve as the source for the download link later.

Step 2Create a Merge Template in Zoho Writer

Head over to Zoho Writer and create a new document template. Insert dynamic merge fields that match your Creator form fields:

  • ${Plant_Name}
  • ${Organisation_Name}

These placeholders will be replaced with real record data at runtime.

Step 3Publish the Creator Report

Publishing your report is mandatory — external APIs cannot access your data without it, and the Perma Link required for the download URL is only generated after publishing.

For Creator 5.0:

Application → Edit Application → Settings → Publish → Publish Component → Select your report (e.g., All Plants)

For Creator 6.0:

Creator Home → Operations → Publish → Select Application → Choose your report (e.g., All Plants)

Step 4Copy the Published Perma Link

After publishing, copy the Perma Link URL of the report. You'll extract a unique token from this URL to build the public file download link in the Deluge script.

Example Perma Link format:

https://creatorapp.zohopublic.in/account_owner/app_name/report-perma/All_Plants/xxxxxxxx

The value after All_Plants/ is the token you will use in the script.

Step 5Create Two API Connections in Zoho Creator

Connection 1 — Zoho Writer

  • Name suggestion: monthlyreporttowriter
  • Purpose: Fetch (download) the merged document from Zoho Writer
  • Required scopes: Document download access

Connection 2 — Zoho Creator

  • Name suggestion: creator
  • Purpose: Upload the document to the File Upload field in Creator
  • Required scopes: File upload access

Step 6Add a Custom Button to the Report

Open your All Plants report in Creator and add a Custom Button (e.g., labeled "Download"). Configure it to trigger a Deluge workflow that calls your custom function.

Step 7Write the Deluge Custom Function

Create a new Deluge function in Zoho Creator and paste the following script:

void Download.mergeNdownload(int Plant_id)
{
    // Replace with your Zoho Writer Template Document ID
    documentid = "nmu7l7ef392baacfd4196a2881698cbdxxxxx";

    download_header = Map();
    download_header.put("Content-Type","application/octet-stream");
    download_header.put("Content-Transfer-Encoding","utf-8");
    download_header.put("Content-disposition","attachment; filename=plant_report.pdf");

    merge_values = Map();
    merge_values.put("subject","Plant Report");
    merge_values.put("message","Auto-generated report");
    merge_values.put("merge_data",{"data":{}});

    // Step 1: Download the merged document from Zoho Writer
    url = "https://zohoapis.in/writer/api/v1/download/" + documentid;

    documentObj = invokeurl
    [
        url :url
        type :GET
        headers:download_header
        connection:"monthlyreporttowriter"
    ];

    // Step 2: Upload the document to Creator File Upload field
    documentObj.setparamname("file");
    account_owner_name = zoho.appuri;

    upload_url = "https://creator.zoho.in/api/v2"
                 + account_owner_name
                 + "report/All_Plants/"
                 + Plant_id
                 + "/File_upload/upload";

    response = invokeurl
    [
        url :upload_url
        type :POST
        files:documentObj
        connection:"creator"
    ];

    info response;

    // Step 3: Build the public download link and open it
    plant = Plants[ID == input.Plant_id];
    file = plant.File_upload;

    // Replace "xxxxxxxx" with the token from your Perma Link
    token = "xxxxxxxx";

    download_link_public = "https://creatorapp.zohopublic.in/file"
                           + account_owner_name
                           + "All_Plants/"
                           + Plant_id
                           + "/File_upload/download/"
                           + token
                           + "?filepath=/"
                           + file;

    openUrl(download_link_public, "new window");
}

Understanding the Script

Here is what each section of the Deluge function does:

  • Download from Writer: Sends a GET request to the Zoho Writer API with your template's document ID, retrieving the merged PDF.
  • Upload to Creator: POSTs the downloaded file to the File Upload field of the matching Plant record in Creator via the Creator API.
  • Build the download link: Constructs a public URL using the Perma Link token and the file path from the uploaded record.
  • Open URL: Calls openUrl() to trigger the file download in a new browser window.
 Important: Replace nmu7l7ef392baacfd4196a2881698cbdxxxxx with your actual Zoho Writer template document ID, and xxxxxxxx with the token from your published report's Perma Link.

Expected Output

✅ The Writer template is merged with the selected plant's data

✅ The generated document is stored in the Creator record's File Upload field

✅ A public download link is generated automatically

✅ The document downloads to the user's local system instantly — no manual steps

Common Errors & Fixes

Problem Likely Cause Fix
File not downloading Incorrect token or broken public link Re-check the Perma Link token and URL structure
API not responding Missing or incorrect connection scopes Verify both API connections have the required permissions
Upload fails File Upload field not configured properly Ensure the field exists in the form and is mapped correctly in the URL
Merge fields are blank Field names mismatch between Creator and Writer template Double-check merge field names match exactly

Pro Tips

  • Always test with a sample record before deploying to production users.
  • Keep your API connections scoped to the minimum required permissions.
  • Use descriptive naming for your Deluge functions to keep maintenance easy.
  • Log API responses using info response; during development and remove before go-live.

Who Is This For?

  • Zoho developers building document automation workflows
  • Operations teams generating plant, inventory, or compliance reports
  • Businesses that need branded, data-driven documents on demand

Conclusion

By connecting Zoho Creator and Zoho Writer through Deluge, you can eliminate one of the most repetitive tasks in document management — manual report generation and download. With a single button click, your users get a fully merged, formatted document saved to their system automatically.

In our next tutorial, we cover a related scenario: fetching a Zoho Books invoice PDF and downloading it through Zoho Creator. Stay tuned!

Post a Comment