Scenario 1: Download a Zoho Writer Merge Template to the Local System from Zoho Creator
Example:
Suppose you have a Plant form that contains plant-related fields such as Plant Name and Organisation Name. The requirement is to merge the selected plant details into a Zoho Writer template and allow the user to download the generated document to their local system.
Steps:
Add a File Upload field in the respective Creator form (e.g., Plant form).
Create a merge template in Zoho Writer using the required fields.
Publish the Creator form report in Zoho Creator (e.g., All Plants report).
- For Zoho Creator 5.0:Go to Zoho Creator Application → Edit Application → Settings (gear icon) → Publish → Publish Component, then select the respective report (e.g., All Plants).
- For Zoho Creator 6.0:Go to the Creator Solutions/Home page → Operations → Publish → Select Application, and then choose the report you want to publish (e.g., All Plants).
Note:
Publishing the report is required to access the data externally for merging it with the Zoho Writer template and enabling the download to the user's local system.
4. Copy the Published URL (Perma Link)
After publishing the report, copy the Perma Link URL. This link will be required later to generate the download URL for the uploaded file.
5. Create the Required Connections in Zoho Creator
You need to create two connections:
a. Zoho Writer Connection
Create a connection in Zoho Creator (for example: monthlyreporttowriter) with the required scopes for the Zoho Writer Download API.
Refer to the Zoho Writer API documentation:
https://www.zoho.com/writer/help/api/v1/download-document.html
b. Zoho Creator Connection
Create another connection (for example: creator) with the required scopes for the File Upload API in Zoho Creator.
Refer to the API documentation:
https://www.zoho.com/creator/help/api/v2.1/upload-file.html
6. Create a Button in the Plant Report
Add a custom button in the Plant report and attach a workflow that triggers a custom function when the button is clicked.
7. Write a Custom Function in Zoho Creator
Create a Deluge custom function that will:
- Merge the form data with the Zoho Writer template
- Upload the generated document to the File Upload field
- Generate a download link
- Automatically download the file to the user’s local system
Deluge Script Example -
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=qeqweqw.pdf");
merge_values = Map();
// Customize subject and message as needed
merge_values.put("subject","Test subject");
merge_values.put("message","Testing");
merge_values.put("merge_data",{"data":{}});
otherparam = Map();
url = "https://zohoapis.in/writer/api/v1/download/"+documentid ;
documentObj = invokeurl
[
url :url
type :GET
headers:download_header
connection:"monthlyreporttowriter"
];
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: Download from that upload field & Plant_id = Zoho Creator Record ID (BigInt)
plant = Plants[ID == input.Plant_id];
file = plant.File_upload;
/*
Example Perma Link:
https://creatorapp.zohopublic.in/account_owner_name/app_link_name/report-perma/All_Plants/xxxxxxxx
Copy the token value after the report name (i.e All_Plants) and replace it below.
*/
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");
}
Scenario 2 : How to Upload a Zoho Book Invoice in File Upload Field & Download into the Local system
Deluge script :-
string Download_PDF_Function(int invoiceID)
{
//---------------- Fetch Invoice Record from Creator ----------------//
inv = Invoices[ID == invoiceID];
// Zoho Books Invoice ID (Long numeric ID)
invoiceID_v = inv.Invoice_ID;
// Zoho Books Organization ID
Organization_ID = inv.Organization_ID;
//---------------- Fetch Invoice PDF from Zoho Books ----------------//
url_v = "https://www.zohoapis.com/books/v3/invoices/pdf?organization_id="
+ Organization_ID + "&invoice_ids=" + invoiceID_v;
documentObj = invokeurl
[
url : url_v
type : GET
connection : "zoho_books"
];
documentObj.setparamname("file");
fileName = inv.Invoice_No + ".pdf";
documentObj.setFileName(fileName);
//---------------- Upload the PDF to Zoho Creator File Upload Field ----------------//
account_owner_name = zoho.appuri;
upload_url = "https://www.zohoapis.com/creator/v2/data" + account_owner_name + "report/All_Invoices/" + invoiceID + "/File_upload/upload";
response = invokeurl
[
url : upload_url
type : POST
files : documentObj
connection : "zcreator"
];
info response;
//---------------- Generate Public Download Link ----------------//
if(response.getJSON("data").size() > 0)
{
file = response.getJSON("data").getJSON("filepath");
info file;
// Replace with your public file access token
token = "xxxxxx";
download_link_public = "https://creatorapp.zohopublic.com/file" + account_owner_name + "All_Invoices/" + invoiceID + "/File_upload/download/" + token + "?filepath=/" + file;
return download_link_public;
}
return "No file Upload";
}