Requirement
Create a template that has a watermark using the pages component in Creator. On click of a custom button, your application's users will be able to download their data populated on the template.
Use Case
A software company uses an Employee Management application to perform various employee related operations including maintaining their payroll. Employees will have access to their Salary Structure report. If they wish to download their salary structure, they can simply click the Download button that will be available next to each record. The salary structure will be downloaded to their local drive in the designed format with the company's logo added as a watermark.
Steps to follow
Form | Form Link Name | Field Type | Field Name | Field Link Name |
Add Organization | Add_Organization | Single Line | Organization Name | Organization_Name |
Image | Logo | Logo |
Phone | Phone Number | Phone_Number |
Address | Address | Address |
Add Employee | Add_Employee | Name | Name | Name |
Phone | Mobile Number | Mobile_Number |
Email | Official Email | Official_Email |
Number | Employee ID | Employee_ID |
Single Line | Department | Department |
Single Line | Designation | Designation |
Single Line | Date of Joining | Date_of_Joining |
Salary Structure | Salary_Structure | Lookup (Add_Employee form) | Employee | Employee |
Dropdown (Imported with predefined choices - Months of the year) | Month | Month_field |
Currency | Basic | Basic |
Currency | HRA | HRA |
Currency | Allowance | Allowance |
Currency | PF | PF |
Currency | CTC | CTC |
3. Include an
HTML snippet block into it. We'll use this HTML snippet block to design the salary structure template.
4. Save the following snippets into the block to create an HTML template based on which the salary structure needs to be downloaded. This snippet also adds the organization logo as watermark to the template.
i. Fetch required values from the Salary Structure, Add employee, and Add Organization forms.
- <%{
- salary_rec = Salary_Structure[ID == recid.toLong()];
- org_rec = Add_Organization[ID != 0];
- employee_rec = Add_Employee[ID == salary_rec.Employee];
ii. Construct the image download URL for the company's logo that is stored in Add Organization form. This image will be added as the watermark.
iii. Define watermark style using CSS.
- <style>
- #watermark
- {
- position: absolute;
- opacity: 0.3;
- text-align: center;
- height: 100%;
- width: 100%;
- box-sizing: border-box;
- }
- #watermark img
- {
- transform: translateY(100%);
- }
- </style>
iv. Construct the template using HTML.
Note: The following snippet constructs a very basic template. You can customize this based on your requirements.
- <div id="watermark"><img src="<%=image%>"></div>
- <div style="padding:20px 40px">
- <div ><center> <b style="font-size: 25px;"><%=org_rec.Organization_Name%></b></center><br>
- <div style="font-size: 15px;color: #515151;word-break: initial;display:inline">
- <center><%=org_rec.Address%><br />Phone: <%=org_rec.Phone_Number%></center></div>
- </div>
- <p><b style="font-size: 20px;">CTC structure for the month of <%=salary_rec.Month_field%></b> <br></p>
- <div> <b>Employee ID: </b><%=employee_rec.Employee_ID%> </div>
- <div> <b>Name: </b><%=employee_rec.Name%> </div>
- <div> <b>Email: </b><%=employee_rec.Official_Email%> </div>
- <div> <b>Department: </b><%=employee_rec.Department%> </div>
- <div> <b>Designation: </b><%=employee_rec.Designation%> </div>
- <div> <b>Date Of Joining: </b><%=employee_rec.Date_of_Joining%> </div>
- <p><br></p>
- <div> <b>Basic: </b><%=salary_rec.Basic%> </div>
- <div> <b>HRA: </b><%=salary_rec.HRA%> </div>
- <div> <b>Allowance: </b><%=salary_rec.Allowance%> </div>
- <div> <b>PF: </b><%=salary_rec.PF%> </div>
- <p><br></p>
- <div> <b>Monthly CTC: </b><%=salary_rec.CTC%> </div>
- </div>
- <%
- }%>
5. Salary structure of all the employees are maintained in the All_Salary_Structure report. However, admin can view and access all the reports and employees should be able to view and download only their records. To achieve this, go to the Design tab of All Salary Structure report and click Open Report Properties button.
6. Click Filters under Organized Records and add the following criteria.
7. Now, let's add a custom button to the All_Salary_Structure report. Click the Layout tab under Quick View in the Report Customization - Web.
8. Click +Add Fields, scroll down and click +Add New Button under Buttons.
9. Provide the following details and click Create Workflow.
10. Click Add New Action > Deluge Script > Create your own, and add the following snippet:
The snippet uses the
openURL task to open the
Download Salary Structure page. The data of the current record will be populated in the HTML template we added (in the 4th step) to
Download Salary Structure page.
11. The
Download Salary Structure page is meant to be used only as a template while downloading the salary structure. Therefore, hide the page using
sections so the users will not be able to access it while accessing the application.
12.
Add the employees as users of the application for them to access the
All Salary Structure report and download the
Download Salary Structure page.
See how it works
Points to note
- This tutorial assumes the app is created in .com DC. To use the same script in different DCs, change the URLs in step 4.ii and step 10 accordingly.
- The Organization Details report needs to be published in order to use the logo image stored in it as a watermark in the file that will be downloaded.
- Make sure the employee has access to both All Salary structure report and Download Salary structure page.
- Pages
- openURL task
- Add users
- Custom Action
- Filters