For Zoho Services only:


I'm actually part of something bigger at Ascent Business Solutions recognized as the top Zoho Premium Solutions Partner in the United Kingdom.

Ascent Business Solutions offer support for smaller technical fixes and projects for larger developments, such as migrating to a ZohoCRM.  A team rather than a one-man-band is always available to ensure seamless progress and address any concerns. You'll find our competitive support rates with flexible, no-expiration bundles at http://ascentbusiness.co.uk/zoho-support-2.  For larger projects, check our bespoke pricing structure and receive dedicated support from our hands-on project consultants and developers at http://ascentbusiness.co.uk/crm-solutions/zoho-crm-packages-prices.

The team I manage specializes in coding API integrations between Zoho and third-party finance/commerce suites such as Xero, Shopify, WooCommerce, and eBay; to name but a few.  Our passion lies in creating innovative solutions where others have fallen short as well as working with new businesses, new sectors, and new ideas.  Our success is measured by the growth and ROI we deliver for clients, such as transforming a garden shed hobby into a 250k monthly turnover operation or generating a +60% return in just three days after launch through online payments and a streamlined e-commerce solution, replacing a paper-based system.

If you're looking for a partner who can help you drive growth and success, we'd love to work with you.  You can reach out to us on 0121 392 8140 (UK) or info@ascentbusiness.co.uk.  You can also visit our website at http://ascentbusiness.co.uk.

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 :: Article: 776

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

Related Articles

Joes Revolver Map

Accreditation

Badge - Certified Zoho Creator Associate
Badge - Certified Zoho Creator Associate

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
© 2024 Joel Lipman .com. All Rights Reserved.