Requirement
Use Deluge to extract a ZIP file and email the extracted files
with the
click of a button.
Use Case
An HR management application contains three forms:
Add Employee
,
Employee Payslips
,
and
Download My Payslips
. The
Add Employee
form maintains the profiles of all employees. The
Employee Payslips
form is
used
to store payslips of all employees. At the end of each year, the HR (admin) uploads payslips of all employees as zip files into the
Employee Payslips
form. This form is accessible only by the admin. However, the employees can get their payslips using the
Download My Payslips
stateless form. When an employee requests for a payslip using the form, the selected month's payslip will be extracted from the zip file of the selected year (stored in Employee Payslips form) and sent as an email to the employee's email address.
Steps to follow
|
Form
|
Form Link Name
|
Field Name
|
Field Link Name
|
Field Type
|
|
Add Employee
|
Add_Employee
|
Official Email
|
Official_Email
|
Email
|
|
Employee ID
|
Employee_ID
|
Number
|
|
This use case requires only the above-mentioned fields. You can include as many fields as required.
|
|
Employee Payslip
|
Employee_Payslip
|
Employee Email
|
Employee_Email
|
Email
|
|
|
Payslips
|
Payslips
|
Subform
|
|
|
Download_My_Payslip
|
Employee ID
|
Employee_ID
|
Lookup (Add_Employee)
|
|
Enter Year
|
Enter_Year
|
Number
|
|
Select Month
|
Select_Month
|
Dropdown
|
We have created the
Download My Payslip
form as stateless because we do not require the data provided to the form be stored in the application.
In order to
create a stateless form
, you will need to create a
regular form
with required fields and duplicate the form with the "Data will be stored in Zoho Creator" checkbox unchecked.
2.
Remove the
Submit
and
Reset
default buttons
and add a button named
Get Payslip
in the
Download
My
Payslip
stateless form. You can also choose to retain the
Reset
button
,
if required.
4. Save the following script in the Deluge Editor:
- // Disable field
- disable Employee_ID;
-
- // Assign the record ID of the logged in employee's record in Add_Employee form to the Employee_ID lookup field
- input.Employee_ID = Add_Employee[Official_Email == zoho.loginuserid].ID;
5. Create a
connection
to Zoho Creator service named "creator_oauth_connection". This connection will be used in the Deluge script in
step 7
to download file.
7.
Click
Add New Action
and select Deluge script. Save the following
Deluge script
in the Deluge editor:
- // Fetch employee record of the logged in employee from Employee_Payslip Form
- empRecord = Employee_Payslip[Employee_Email == zoho.loginuserid];
-
- //Iterate through the subform that holds employee's payslips as zip files
- for each subformRow in empRecord.Payslips
- {
-
- //Find the subform row that holds the payslip zip file of the requested year
- if(subformRow.Year_field == Enter_Year)
- {
-
- //Download the requested year's payslip zip file using Zoho Creator V2 API
- //Replace <app_admin_name> and <application_link_name> with appropriate values
- zip_file = invokeurl
- [
- url :" https://creator.zoho.com/api/v2/<app_admin_name>/<application_link_name>/report/All_Employee_Payslips/" + empRecord.ID + "/Payslips.Payslip_ZIP/" + subformRow.ID + "/download"
- type :GET
- connection:"creator_oauth_connection"
- ];
-
- // Extract the zip file to get pdf files containing payslip of individual months
- extractedFiles = zip_file.extract();
-
- //The extracted files are returned as Map in which the keys are file name and values are their corresponding pdf file
- //Assuming the file names are stored in the format EmployeeID-Month-Year.pdf, construct file name of the requested payslip
- fileName = input.Employee_ID.Employee_ID + "-" + input.Select_Month + "-" + input.Enter_Year + ".pdf";
-
- /Get the required payslip from the extracted file
- requestedFile = extractedFiles.get(fileName);
-
- //Send the requested payslip as mail
- sendmail
- [
- from :zoho.adminuserid
- to :zoho.loginuserid
- subject :"Payslip" + "-" + input.Select_Month + " " + input.Enter_Year
- message :"Please find your requested payslip in the attachments"
- Attachments :file:requestedFile
- ]
-
- //Display an acknowledgement message
- alert "The requested payslip has been sent as email";
- }
- }
See how it works
Points to note
-
The Deluge script provided in this tutorial is specific to the ZIP files that contai
s 12 PDF files each corresponding to months of a year. For the script to work as expected, the filenames of the PDF files must be in the format:
<employeeID>-<month>-<year>.pdf
.
Example: 2406-January-2020
Please check the attachments for the sample file on which the provided Deluge script works.