For Zoho services only


I'm currently part of a wider delivery team at Ascent Business Solutions, recognised as a leading Zoho Premium Solutions Partner in the United Kingdom.

Ascent Business Solutions support organisations with everything from targeted technical fixes through to full Zoho CRM implementations and long-term platform adoption. Working as a team rather than a one-person consultancy allows projects to move forward consistently, with access to the right skills at each stage.

The team I manage specialises in API integrations between Zoho and third-party finance and commerce platforms such as Xero, Shopify, WooCommerce, and eBay. Much of our work involves solving integration challenges that fall outside standard documentation, supporting new ideas, new sectors, and evolving business models.

Success is measured through practical outcomes and return on investment, ranging from scaling small operations into high-turnover businesses to delivering rapid gains through online payments, automation, and streamlined digital workflows.

If you are looking for structured Zoho expertise backed by an established consultancy, you can contact Ascent Business Solutions on 0121 392 8140 (UK), email info@ascentbusiness.co.uk, or visit https://www.ascentbusiness.co.uk.
Zoho CRM: Get Unique Values of a Text Field

Zoho CRM: Get Unique Values of a Text Field

What?
This article demonstrates how to return a list of unique values in a particular field in a CRM module.

Why?
My use-case is a data-migration where the records exist in a staging module in CRM but I want to transform/translate one of the column values into the target

How?
So this is my plan:
  1. Setup a connector to CRM with the scopes ZohoCRM.coql.READ and ZohoCRM.modules.ALL
  2. Build up a SQL query, or more specifically, a COQL - CRM Object Query Language
  3. Try using distinct on a single-line text field
  4. Adapt the query for unique values in a lookup field

I won't demonstrate how to set up a connector as there is plenty of documentation on the Zoho Official Documentation and even on this website so we'll skip to the COQL query. This is what I have:
copyraw
// 
// build up COQL query 
v_CoqlQuery = "select distinct Currency from Quotes where Subject!=''"; 
// 
// build up parameters 
m_Params = Map(); 
m_Params.put("select_query",v_CoqlQuery); 
// 
// invokeUrl 
r_Coql = invokeUrl 
[ 
    url :"https://www.zohoapis.eu/crm/v2/coql" 
    type :POST 
    parameters: m_Params.toString() 
    connection: "joels_coql_connection" 
]; 
//
// output
info r_Coql;
  1.  // 
  2.  // build up COQL query 
  3.  v_CoqlQuery = "select distinct Currency from Quotes where Subject!=''"
  4.  // 
  5.  // build up parameters 
  6.  m_Params = Map()
  7.  m_Params.put("select_query",v_CoqlQuery)
  8.  // 
  9.  // invokeUrl 
  10.  r_Coql = invokeUrl 
  11.  [ 
  12.      url :"https://www.zohoapis.eu/crm/v2/coql" 
  13.      type :POST 
  14.      parameters: m_Params.toString() 
  15.      connection: "joels_coql_connection" 
  16.  ]
  17.  // 
  18.  // output 
  19.  info r_Coql; 
But this returns something like the following (I've reduced the 200 records to about 6 of them):
copyraw
{
  "data": [
    {
      "Currency": "EUR",
      "id": "123456789000000001"
    },
    {
      "Currency": "EUR",
      "id": "123456789000000002"
    },
    {
      "Currency": "EUR",
      "id": "123456789000000003"
    },
    {
      "Currency": "GBP",
      "id": "123456789000000004"
    },
    {
      "Currency": "USD",
      "id": "123456789000000005"
    },
    {
      "Currency": "USD",
      "id": "123456789000000006"
    }
  ],
  "info": {
    "count": 200,
    "more_records": true
  }
}
  1.  { 
  2.    "data": [ 
  3.      { 
  4.        "Currency": "EUR", 
  5.        "id": "123456789000000001" 
  6.      }, 
  7.      { 
  8.        "Currency": "EUR", 
  9.        "id": "123456789000000002" 
  10.      }, 
  11.      { 
  12.        "Currency": "EUR", 
  13.        "id": "123456789000000003" 
  14.      }, 
  15.      { 
  16.        "Currency": "GBP", 
  17.        "id": "123456789000000004" 
  18.      }, 
  19.      { 
  20.        "Currency": "USD", 
  21.        "id": "123456789000000005" 
  22.      }, 
  23.      { 
  24.        "Currency": "USD", 
  25.        "id": "123456789000000006" 
  26.      } 
  27.    ], 
  28.    "info": { 
  29.      "count": 200, 
  30.      "more_records": true 
  31.    } 
  32.  } 
Which isn't what I want because it has returned the same currency several times and thinks they're unique/distinct because the IDs of each quote record are different.

Having spoken to Zoho and raised with the Zoho Deluge team... Well, they realised they would get the same results, and then suggested looping through all records and creating a distinct list variable... But what if there are 20000+ records?

The advantage of working in a team of Zoho developers, is that "two heads are better than one" does apply more than we think. A colleague of mine suggested adding a group by to the query which works (tested with both the keyword 'distinct' and without it with no difference in the response):
copyraw
// 
// build up COQL query 
v_CoqlQuery = "select Currency from Quotes where Subject!='' group by Currency"; 
// 
// build up parameters 
m_Params = Map(); 
m_Params.put("select_query",v_CoqlQuery); 
// 
// invokeUrl 
r_Coql = invokeUrl 
[ 
    url :"https://www.zohoapis.eu/crm/v2/coql" 
    type :POST 
    parameters:m_Params.toString() 
    connection:"joels_coql_connection" 
]; 
//
// output
info r_Coql;
  1.  // 
  2.  // build up COQL query 
  3.  v_CoqlQuery = "select Currency from Quotes where Subject!='' group by Currency"
  4.  // 
  5.  // build up parameters 
  6.  m_Params = Map()
  7.  m_Params.put("select_query",v_CoqlQuery)
  8.  // 
  9.  // invokeUrl 
  10.  r_Coql = invokeUrl 
  11.  [ 
  12.      url :"https://www.zohoapis.eu/crm/v2/coql" 
  13.      type :POST 
  14.      parameters:m_Params.toString() 
  15.      connection:"joels_coql_connection" 
  16.  ]
  17.  // 
  18.  // output 
  19.  info r_Coql; 
Which returns something like the following:
copyraw
{
  "data": [
    {
      "Currency": "EUR",
      "id": "123456789000000001"
    },
    {
      "Currency": "GBP",
      "id": "123456789000000004"
    },
    {
      "Currency": "USD",
      "id": "123456789000000005"
    }
  ],
  "info": {
    "count": 3,
    "more_records": false
  }
}
  1.  { 
  2.    "data": [ 
  3.      { 
  4.        "Currency": "EUR", 
  5.        "id": "123456789000000001" 
  6.      }, 
  7.      { 
  8.        "Currency": "GBP", 
  9.        "id": "123456789000000004" 
  10.      }, 
  11.      { 
  12.        "Currency": "USD", 
  13.        "id": "123456789000000005" 
  14.      } 
  15.    ], 
  16.    "info": { 
  17.      "count": 3, 
  18.      "more_records": false 
  19.    } 
  20.  } 

Amazing! Let's go one further for a lookup field, in this case the account name field on the quotes record:
copyraw
// 
// build up COQL query 
v_CoqlQuery = "select Account_Name.Account_Name from Quotes where Subject!='' group by Account_Name.Account_Name"; 
// 
// build up parameters 
m_Params = Map(); 
m_Params.put("select_query",v_CoqlQuery); 
// 
// invokeUrl 
r_Coql = invokeUrl 
[ 
    url :"https://www.zohoapis.eu/crm/v2/coql" 
    type :POST 
    parameters:m_Params.toString() 
    connection:"joels_coql_connection" 
]; 
//
// output
info r_Coql;
  1.  // 
  2.  // build up COQL query 
  3.  v_CoqlQuery = "select Account_Name.Account_Name from Quotes where Subject!='' group by Account_Name.Account_Name"
  4.  // 
  5.  // build up parameters 
  6.  m_Params = Map()
  7.  m_Params.put("select_query",v_CoqlQuery)
  8.  // 
  9.  // invokeUrl 
  10.  r_Coql = invokeUrl 
  11.  [ 
  12.      url :"https://www.zohoapis.eu/crm/v2/coql" 
  13.      type :POST 
  14.      parameters:m_Params.toString() 
  15.      connection:"joels_coql_connection" 
  16.  ]
  17.  // 
  18.  // output 
  19.  info r_Coql; 

Additional
If you wanted the unique values of a picklist/dropdown, then consider an invokeUrl looping through the fields settings in CRM.

Source(s):
Category: Zoho CRM :: Article: 312

Joes Word Cloud

Accreditation

Badge - Zoho Creator Certified Developer Associate
Badge - Zoho Deluge Certified Developer
Badge - Certified Zoho CRM Developer

Donate & Support

If you like my content, and would like to support this sharing site, feel free to donate using a method below:

Paypal:
Donate to Joel Lipman via PayPal

Bitcoin:
Donate to Joel Lipman with Bitcoin bc1qf6elrdxc968h0k673l2djc9wrpazhqtxw8qqp4

Ethereum:
Donate to Joel Lipman with Ethereum 0xb038962F3809b425D661EF5D22294Cf45E02FebF

Credit where Credit is Due:


Feel free to copy, redistribute and share this information. All that we ask is that you attribute credit and possibly even a link back to this website as it really helps in our search engine rankings.

Disclaimer: Please note that the information provided on this website is intended for informational purposes only and does not represent a warranty. The opinions expressed are those of the author only. We recommend testing any solutions in a development environment before implementing them in production. The articles are based on our good faith efforts and were current at the time of writing, reflecting our practical experience in a commercial setting.

Thank you for visiting and, as always, we hope this website was of some use to you!

Kind Regards,

Joel Lipman
www.joellipman.com