For Zoho Services only:


I'm actually part of a bigger team at Ascent Business Solutions where we have support technicians and project consultants. Support is for smaller technical fixes but this can include developments, reports or integrations; depending on the size of the task. Projects are for more time-consuming developments such as revamps of the Zoho Suite of apps or on-site training. The advantage of a team is that if I am out-of-office for a day or so, there is always someone at Ascent Business Solutions who can deal with any queries/issues you may have.

Our support rates can be found and purchased at http://ascentbusiness.co.uk/zoho-support-2. A support bundle doesn't have an expiry date. So whether we can do what you want within the bundle and a year later need further support, if there are minutes left on the bundle then there is no additional charge.

Our project rates for bigger developments can be found at http://ascentbusiness.co.uk/crm-solutions/zoho-crm-packages-prices and will involve a dedicated project consultant along with developers who will hold your hand through the development process.

If you want help building a solution for one of the Zoho Apps in the Zoho Suite, contact us on 0121 293 8140 (UK) or by email at info@ascentbusiness.co.uk. You can also visit our website at http://ascentbusiness.co.uk.

I regularly build and specialize in 2-way API integrations for Xero, Shopify and eBay.

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: The information on this website is provided without warranty and any content is merely the opinion of the author. Please try to test in development environments prior to adapting them to your production environments. The articles are written in good faith and, at the time of print, are working examples used 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 - Valid till 8 May 2022 3QnhmaBX7LQSRsC9hh6Je9rGQKEGNQNfPb
© 2021 Joel Lipman .com. All Rights Reserved.