Get Related Records from Zoho CRM
Table of Contentsup
Overview
Fetch dynamic records related to a particular module from Zoho CRM, using zoho.crm.getRelatedRecords() task in Zoho Creator. For instance, Notes attached to a particular Lead or Contacts linked to a particular account can be fetched using the ID of the parent module record.
Syntax
<response>=zoho.crm.getRelatedRecords(<relation_name>, <parent_module_name>, <record_id>, [<page>],[<per_page>]);
where,
Params | Description | Data type | ||||||||||||
<response> | is the response returned by Zoho CRM. | LIST | ||||||||||||
<relation_name> | is the API name of the related list. Note: Refer this for instructions to view the related list of each module in your account. | STRING | ||||||||||||
<parent_module_name> | API name of the Module to which the sub module belongs. For example "Notes" submodule belongs to "Leads" parent module. Following is the list of supported modules
Note: Refer this for the instructions to get API names of the CRM modules and fields. | STRING | ||||||||||||
<record_id> | ID of the parent module record whose related data needs to be fetched You can fetch record IDs from the response returned using the Fetch Records task | BIGINT | ||||||||||||
<page> (optional) | is the starting index of the records that need to be fetched. Default value: 1. | BIGINT | ||||||||||||
<per_page> (optional) | Used to get the list of records available per page. Default value: 200. | BIGINT |
Example 1: Fetch Notes from Leads module
In this example, we will fetch Notes from a Zoho CRM Lead record by specifying the record ID. Assume we have a Zoho Creator Form with LeadID field(Integration field type with service as Zoho CRM and module as Leads). To fetch Notes from the selected Lead, add the following script in the required workflow section:
notesinfo = zoho.crm.getRelatedRecords("Notes", "Leads", input.LeadID);
where,
notesinfo
"Notes"
"Leads"
input.LeadID
Example 2: Fetch Contacts from Accounts module
In this example, we will fetch Contacts from a record in Zoho CRM Accounts module by specifying the record ID. Assume we have a Zoho Creator Form with AccountID field(Integration field type with service as Zoho CRM and module as Accounts). To fetch Contacts from the selected Account, add the following script in the required workflow section:
contactsinfo = zoho.crm.getRelatedRecords("Contacts", "Accounts", input.AccountID, 1, 10);
where,
contactinfo
"Contacts"
"Accounts"
input.AccountID
1 and 10
Example 3: Fetch Events related to a Custom Module
In this example, we will fetch Events from a Custom Module record by specifying the record ID. To achieve this add the following script in the required workflow section:
eventsinfo = zoho.crm.getRelatedRecords("Events", "Hotels", customModuleID, 1, 3);
where,
eventsinfo
"Events"
"Hotels"
customModuleID
1 and 3
Response Format
The response returned is of the following format:
{
"Owner":{
"name":"<value>",
"id":"<value>"
},
"<field_api_name>":"<field_value>",
"Modified_By":{
"name":"<value>",
"id":"<value>"
},
},
"Modified_Time":"<value>",
"Created_Time":"<value>",
{
},
"Created_By":{
"name":"<value>",
"id":"<value>"
},
}
Note:
The following is a sample response returned when related records are fetched:
{
"Owner":{
"name":"Ben",
"id":"2938383000000132011"
},
"Company":"Zillum",
"Email":"bruce.wills@zillum.com",
"Description":null,
"Discount":null,
"$currency_symbol":"$",
"Total_Amount":null,
"Rating":null,
"Website":null,
"Twitter":null,
"Salutation":null,
"Last_Activity_Time":null,
"First_Name":null,
"Full_Name":"Wills",
"Lead_Status":null,
"Industry":null,
"Modified_By":{
"name":"Ben",
"id":"2938383000000132011"
},
"Skype_ID":null,
"$converted":false,
"$process_flow":false,
"Phone":"+1 678 904 1854",
"Street":null,
"Zip_Code":null,
"id":"2938383000000399001",
"Email_Opt_Out":false,
"$approved":true,
"Designation":null,
"$approval":{
"delegate":false,
"approve":false,
"reject":false,
"resubmit":false
},
"Modified_Time":"2018-03-28T11:34:40+05:30",
"Created_Time":"2018-03-28T11:34:40+05:30",
"$converted_detail":{
},
"$followed":false,
"$editable":true,
"City":null,
"No_of_Employees":0,
"Mobile":null,
"Last_Name":"Wills",
"State":null,
"Total":0,
"Lead_Source":null,
"Country":"United States",
"Tag":[
],
"Created_By":{
"name":"Ben",
"id":"2938383000000132011"
},
"Fax":null,
"Annual_Revenue":0,
"Secondary_Email":null
}
Related Links
- To fetch the string value to which the specified key is mapped, use get()
- To get values from fetched records, use getJSON()
- To convert the json string to list format, use toJSONList().