Get Records from Zoho CRM

Get Records from Zoho CRM

Overview

Fetch records from multiple modules in Zoho CRM, using zoho.crm.getRecords() task in Zoho Creator.

Syntax

<variable>=zoho.crm.getRecords(<module_name>,[<page>],[<per_page>], {<optional_data_map>});

where,

Params DescriptionData type

<variable> 

is the response returned by Zoho CRM.

LIST

<module_name> 

is the API name of the CRM module from where the records will be fetched.

Following is the list of supported modules.

Leads

Deals

Products

Contacts

Campaigns

Vendors

Accounts

Cases

Quotes

Sales_Orders

Purchase_Orders

Invoices

Note: Refer this for the instructions to get API names of the CRM modules and fields.

STRING

<page>

(optional)

To get the list of records based on pages.

Default value: 1.

BIGINT

<per_page>

(optional)

Used to get the list of records available per page.

Default value: 200.

BIGINT

<optional_data_map> 

Used to get the list of records using params other than page and per_page.

MAP

Example 1: Fetch Customer Names from Contacts

Let's assume we have a Zoho Creator Form with Customer Name field to store Customer names. Records can be fetched from Zoho CRM Contact's Module by adding the script shown below in the required workflow section:

contactslist=zoho.crm.getRecords("Contacts");

The Customer Name of each fetched Contact can then be extracted and populated within the Form field using the ui.add() task. This can be achieved by adding the following script:

for each ContactRecord in contactslist{Customer_Name:ui.add(ContactRecord.get("Last_Name"));}

where,

contactslist
is the response returned asmapby Zoho CRM. It holds the records fetched from Zoho CRM’s
Contacts module.
"Contacts"
refers to the Contacts module, of string datatype, in Zoho CRM.
ContactRecord
stands for each unique record fetched from Zoho CRM's Contacts module.
Customer_Name
is the Form field which gets populated with customers' Names.

Example 2: Fetch Invoices and their Products

To fetch records from Invoices module add the following script in the required workflow section:

InvoiceList=zoho.crm.getRecords("Invoices");

where,

InvoiceList
is the response returned, ofmapdatatype, from Zoho CRM.
"Invoices"
refers to the Invoices module, ofstringdatatype, in Zoho CRM.

 

Example 3: Fetch data from a Custom Module

Let's say we have an email field in a Zoho Creator Form. To fetch an email address value for it from a Zoho CRM Custom Module, you can first fetch all the records from the Custom Module. The fetched records can then be iterated, to extract the email value of each record. To fetch records from a Custom Module, add the following script in the required workflow section:

CustomList=zoho.crm.getRecords("Hotels");

where,

CustomList
is the response returned asmapby Zoho CRM. It holds the records fetched from Zoho
CRM’s Custom Module.
"Hotels"
is the API name of the custom module.

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: It is to be noted that all visible fields in the module will be returned, though we have specified only one line saying "<field_api_name" : "<field_value>" to keep the response format of readable length.

The following is a sample response when a lead is fetched from Leads module:

{  
   "Owner":{  
      "name":"Ben",
      "id":"2938383000000132011"
   },
   "Company":"Zylker",
   "Email":"bruce.wills@zylker.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
}

To get the list of record IDs from the response, execute the following snippet:

<list_variable> = list();
<variable> = <response_variable>.toJsonList();
for each <loop_variable> in <variable>
{
<variable1> = <loop_variable>.getJson("id");
<list_variable>.add(variable1);
info <list_variable>;
}

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().

Share this post : FacebookTwitter

Still can't find what you're looking for?

Write to us: support@zohocreator.com