How to Create a Related Record with a Function in Zoho CRM

03.31.23 11:29 AM By Andy

What we are going to do

In this tutorial you are going to code a Deluge function that will create a related record in Zoho CRM. Then, we are going to add the function to a workflow, so it creates the record automatically. For this example, we are going to use the Deals module, that will trigger the automation, and a Custom module called Jobs, where the related record is going to be created. Both records are going to be linked.


  • The modules you want to use have to be already built. If you want to learn how to create a custom module, here's a tutorial:
  • The child module must already contain the fields to receive information from the main module.

Adding a Lookup field

  1. In the Zoho CRM settings, go to "Modules and Fields", and open the "child" module that you are going to link to the main module. In this case, we are going to open the Jobs module, that will be linked to the Deals module.
  2. Open the layout where you are going to add the lookup field.
  3. Drag and drop the lookup field to the layout.
  4. Configure the lookup field:
    1. Name the field.
    2. Select the lookup module. In our case, it it's the Deals module.
    3. Name the related list. This is going to be displayed on the main module. We are going to call it "Jobs".
  5. Click on "Done".
  6. Save the layout and close it.

Setting up the function

  1. In the Zoho CRM settings, go to "Functions" under "Developer Space".
  2. Create a new function: Add a name and select "Automation" as the category.
  3. Copy the function located below and paste it in the text editor in Zoho CRM.
  4. Edit the arguments: add "deal_id" as a string.
  5. Get the Deal variables to pass to the Job:
    1. Find the API Names in the CRM settings.
  6. Map the variables using the Job module API Names.
    1. Make sure to include the "deal_id", so the records link to each other.
  7. Test the function.
  8. Save the function.
deal_info = zoho.crm.getRecordById("Deals",deal_id);
// get information about the deal
deal_name = deal_info.get("Deal_Name");
deal_estimator = deal_info.get("Estimator").get("id");
deal_type = deal_info.get("Type");
closing_date = deal_info.get("Closing_Date");
//create the record name
job_name = "Job: " + deal_name;
//map fields from the deal to the job
mp = Map();
//create the job
create_job = zoho.crm.createRecord("Jobs",mp);
info create_job;

Creating a workflow

  1. In the setup page, click on workflow rules under automations
  2. Create a new rule, select the Deals module, and name it (we are selecting the Deals instead of the contact because we need to trigger this automation when a Deal stage changes)
  3. Configure your workflow trigger and conditions:
    1. When > on a record action > Edit > Stage is modified to the value of Won
    2. Condition: all Deals
  4. As the instant action, select "function"
  5. Click on "new function" and then select "functions"
  6. Find the function you just created, and click on "configure"
  7. Map the argument "deal_id" as the deal ID, using the # key
  8. Click on "save and associate" and save the workflow
  9. Test the workflow