Hi everyone,
Following our Zoho Creator - Tips and Tricks series every fortnight, we are back today with a tip based on one of the most popular questions asked in our forum. This tip would help you fetch data from another application(App B) and use it in your current application(App A).
Just as your application can send data to other applications, similarly it can easily receive data from other applications. This can be easily achieved in Zoho Creator by creating a custom function in the application(App B) from which you need to fetch data.
Functions are nothing but a unit of code written to perform a specific task.
Let's look at simple example to understand how to do this.
To explain this I have created two applications: Travel Request and Employee Details. And both of these applications contain a form each to collect data.
The Raise Travel Request Form in the Travel Request Application allows employees to raise request for their upcoming business trips.
The Add Employees Form in the Employee Details Application stores the all the information about the employees in your organization.
Use Case:
Here when an employee uses the Raise Travel Request Form to raise a request for his travel, we need to fetch the employee's Department and his Manager's Email ID from the Employee Details App and use it to auto-populate the fields in the Raise Travel Request Form based on the Employee Email ID entered.
Step 1: Create a function
To achieve this we need to create a custom function in the Employee Details Application. Navigate to Workflow section and click on Custom Functions. Specify the following arguments to create the following function.
Once you click on CREATE, write the below given Deluge scripts to the function.
- string Getemployeedetails(string Empemail)
- {
- empdepartment = Add_Employee[Email_ID == Empemail].Department;
- manageremail = Add_Employee[Email_ID == Empemail].Manager;
- return empdepartment+","+ manageremail;
- }
Note: This function will return the Employee's department and manager email ID in a format like "Departmentvalue,Manageremailvalue" as a string.
Step 2: Call the function
Now that we have created this function, we need to call this function from the Travel Request Application. By calling the function, we will be able to fetch the required details from the Employee Details Application and autopopulate them in the Raise Travel Request Form.
For this we need to create a workflow On User Input of the Employee Email ID field and write the below given Deluge scripts.
- datavalue = employee_details.Getemployeedetails(input.Employee_Email_ID);
- input.Department = datavalue.getPrefix(",");
- input.Manager = datavalue.getSuffix(",");
Note: As we have configured the Getemployeedetails () function to return string value like "Departmentvalue,Manageremailvalue" , we need to use our built-in function getPrefix() and getSuffix() to get the values before and after comma value respectively.
Voila! That's all you need to do to fetch data from another application. Isn't it easy? Give it a try. If you have any doubts or queries regarding this tip, please feel free to add them as comments below. We would be happy to address them all.