A peek into Deluge's file functions

A peek into Deluge's file functions

Hello everyone,

Recognizing the importance of files in Zoho products, Deluge implements FILE as a unique type of data. It also comes with a set of built-in functions that operate on FILE data type to identify the properties of files, zip or unzip files, and more. In this post, we will cover Deluge file functions that let you work with your digital documents using Deluge.

Files in Deluge
Files in Deluge must be fetched from the web or cloud service. It doesn't operate on offline files. The following are the ways you can bring files into Deluge scripting:
Irrespective of the format, all the files fetched using any of the above-mentioned methods, except the "fetch records" task and "input" keyword, are treated as file objects (or FILE data type). For example, be it a .pdf format file or a .jpeg format file, both are categorized under FILE data type. The files fetched using the "fetch records" task and "input" keyword are not considered as FILE data type, and hence file functions cannot be applied on them. However, such files can be used in integration tasks (for example in attach file crm task), or in the send mail task to send as a file attachment, or to assign the file as a value to another Zoho Creator file field.

File functions
File functions are built-in functions that operate on file objects (or FILE datatype). These functions cannot be applied on files fetched using the Zoho Creator "fetch records" task or "input" keyword.

The following table lists the file functions available in Deluge:

Function
Description
Checks if a variable is of FILE data type.
Converts a TEXT or COLLECTION value into file object. This function is supported in all Zoho services except Creator.
Returns the name of the input file.
Returns the size of the input file.
Returns the content of the input file.
Returns the type of the input file. This function is supported in all Zoho services except Creator.
Renames the input file with the specified name.
Compresses one or more file into a single zip file.
Extracts the content of the input zip file.

Apart from the above-mentioned functions, we also have setCharset, setFileType, and setParamName which can be used only on invoke URL task to set file properties.

Example 1: Uses setFileName and compress functions
Imagine you want to rename a few documents, convert them into a single zip file, and send the compressed zip file as an email attachment. The following example performs these actions in the below order:

  1. Fetches an invoice from Zoho Books. 
  2. Generates file name based on the customer name and current date & time, and renames the fetched invoice using the setFileName function.
  3. Fetches the customer's contract from Zoho Workdrive.
  4. Generates file name based on the customer name and current date & time, and renames the fetched contract using the setFileName function.
  5. Converts the fetched invoice and contract documents into a zip file using compress function.
  6. And lastly, sends the renamed file as attachment of sendMail task.

Step 1:
  1. // Fetch the required invoice from Zoho Books. invoice_pdf variable holds the fetched file object
  2. invoice_pdf = invokeUrl
  3. [
  4. url:"https://books.zoho.com/api/v3/invoices/pdf?organization_id=70XXXX516&invoice_ids=2155XXXXXXXXXXXXXXXX09"
  5. type: GET
  6. connection: "books_connection"
  7. ];

Step 2:
  1. // Generate the file name with customer name and current time. Here, customer_name is the input parameter of the custom function
  2. generated_pdf_name = customer_name + "_invoice_" + zoho.currentTime.toString("dd-MMM-yyyy_hh:mm");

  3. // Rename the file with the generated file name
  4. invoice_pdf.setFileName(generated_pdf_name);

Step 3:
  1. // contract variable holds the document fetched from Zoho Workdrive
  2. contract = invokeUrl
  3. [
  4. url: "https://workdrive.zoho.com/api/v1/download/5crsmXXXXXXXXXXXXXXXXXXXXXXXXXXXf16b8"
  5. type: GET
  6. connection: "workdrive_connection"
  7. ];

Step 4:
  1. // Generate the file name with customer name and current time. Here, customer_name is the input parameter of the custom function
  2. generated_doc_name = customer_name + "_contract_" + zoho.currentTime.toString("dd-MMM-yyyy_hh:mm");

  3. // Rename the file with the generated file name
  4. contract.setFileName(generated_doc_name);

Step 5:
  1. // Create a list to add files that need to be compressed
  2.  filesList = List();
  3.  filesList.add(invoice_pdf);
  4.  filesList.add(contract);

  5.  // Perform compress function
  6.  zip_file = filesList.compress("invoice");

Step 6:
  1. // Send email with the compressed file as attachment
  2. sendmail
  3. [
  4. from: zoho.loginuserid
  5. to: customer_email
  6. subject: "Invoice"
  7. message: "Please check attachment to find your invoice "
  8. attachments: file:  zip_file
  9. ]

Example 2: Uses extract and getFileContent functions
The following example extracts .csv files from a .zip file and uploads the content of the extracted files into a Zoho Sheet worksheet:

Step 1:
  1. // Extract .csv files from .zip file. file_collection holds the extracted files as KEY-VALUE collection
  2. file_collection = compressed_file.extract(); 

Step 2:
  1. // Iterate through the collection to access individual .csv files
  2. for each file in file_collection
  3. {
  4. // Fetch the content of the extracted .csv file
  5. content = file.getFileContent();
  6. // Use Sheet integration task to insert the fetched CSV into the specified Zoho Sheet
  7. response = zoho.sheet.insertCSV("6fbyeXXXXXXXXXXXXXXXXXXXXXXXXXXX44b56", "Sheet1", content);
  8. }

Learn more about file functions from our help documents and do let us know your questions and suggestions in the comments.

    • Sticky Posts

    • Function #41: Sync Associated Subforms!

      Welcome back everyone! The last custom function showed how to update a Contact with Product details from it's Related list in Deals. This week, let's look at a function that lets you update subform records in two modules simultaneously when one of them is updated. Business scenario Let's look at how subform helps in an education institution that has deployed Zoho CRM. National Public School, Austin (made up, of course!) has set up Zoho CRM and it follows the same relationship pattern of "Students",

      Zoho SalesIQ Resources



            Zoho TeamInbox Resources

              Zoho DataPrep Resources


                  Zoho CRM Plus Resources

                    Zoho Books Resources


                      Zoho Subscriptions Resources

                        Zoho Desk Resources

                          Zoho Projects Resources


                            Zoho Sprints Resources


                              Qntrl Resources


                                Zoho Creator Resources


                                  Zoho WorkDrive Resources




                                      Zoho Campaigns Resources

                                        Zoho CRM Resources

                                                    Design. Discuss. Deliver.

                                                    Create visually engaging stories with Zoho Show.

                                                    Get Started Now


                                                      Zoho Show Resources


                                                        Zoho Writer Writer

                                                        Get Started. Write Away!

                                                        Writer is a powerful online word processor, designed for collaborative work.

                                                                  有料プランをご利用の方