Manipulating Multi Select Lookup fields (MxN) using Zoho CRM APIs

Manipulating Multi Select Lookup fields (MxN) using Zoho CRM APIs

Hello everyone!
Welcome back to another week of Kaizen. In last week's post in the Kaizen series, we discussed how subforms work in Zoho CRM and how to manipulate subform data using Zoho CRM APIs.
In this post, we will discuss how to manipulate a multi-select lookup fields using Zoho CRM APIs.

Multi-select lookup field

The Multi-Select Lookup Field enables you to establish a many-to-many relationship between two different modules in CRM. It allows you to associate multiple records with each other, from two different modules. 
These associations are stored in an individual module called "Linking Module". Consider there are two modules, Employees and Skills. The Employees module contains details regarding Zylker's workforce, and the Skills module contains details regarding various skills like Social Media Marketing and Content Marketing.
We want to associate multiple skills to an employee. So, a multi-select lookup can be created in the Employees module. When doing so, similar multi-select lookup field will be automatically created in the Skills module, along with the EmpXSkills linking module by Zoho CRM. The underlying data model is described in the below image.
The above chart shows the data model representation when you create a multi-select lookup field in a module. Here, there are two lookup fields—one pointing to the Employees module and the other pointing to the Skills module.
In the linking module, two lookup fields (lookup fields with api names - Employees and Skills) will be created. The lookup fields, one pointing to Employees and the other pointing to Skills from the linking module, establish a connection between the linking module and its associated module.

How to associate an employee's skills while creating an Employee record through the Insert Records API

API names you need before invoking the API
  • The API name of the multi-select lookup field in the modules you want to insert data.
  • API names of the lookup fields in the linking module. Eg: here the API Name of the linking module is "EmpXSkills" and the corresponding lookup field api names are "Employees" & "Skills". You can use the Fields Metadata API for Employees and Skills to get these details.
Step 1
Know the API name of the multi-select lookup field in the module (In our case, Skills is the multi-select lookup field in the Employees module)

To know the API names of the multi-select lookup fields, make a GET - Fields Metadata API call. Among all the Employee's fields, multi-select lookup field can be identified by the json key data_type with the value multiselectlookup. The corresponding connected module can be found from the json connected_module. Below is the API call & response for such a multi-select lookup field.

Request URL : {api-domain}/crm/v6/settings/fields?module=Employees
Request Method: GET

Sample Response: 

The above highlighted keys are the details of the Multi select lookup field. The corresponding keys are explained below:

"multiselectlookup": {
                "display_label": "Skills",   //Display label of the MxN field in the Employees module
                "linking_module": {
                    "api_name": "EmpXSkills", //API name of the linking module
                    "id": "5725767000002166520"
                ...
                "lookup_apiname": "Employees", //API name of the Employee lookup field in the linking module
                "connected_module": {
                    "api_name": "Skills", //API name of the connected module
                    "id": "5725767000002165263"
                },
                "api_name": "Skills_In_Related_List", //API of the related list of the connected module Skills in the Employees module.
                "connectedfield_apiname": "Employees", //API Name of the multi-select lookup field in the connected module (Skills)
               "connectedlookup_apiname": "Skills", //API name of the Skills module lookup field in the linking module.
                "id": "5725767000002166655" //Related List ID
            },
                ...

Step 2
Using the api_name of the linking module, make a GET Fields metadata API call to get the list of fields (along with their api_name) present in it. It lists all fields of the linking module in the response. 
Sample Request and Response

Search for the "data_type": "lookup" in the response. The lookup fields represent the connected modules in association with the linking module.
For example, in our case, the response will have two lookup fields. One of the lookup fields (with api name Employees) points to the Employees module, and the other one (with api name Skills) points to the Skills module

Step 3
Associate records via the Multi-select lookup field using the Insert Records API

To associate records via the MxN field, you need to know the IDs of the records in the Skills module. Here is the input body to insert the skills in the Employee module with the multi-select lookup field Skills
Here is the input body to insert a new Employee record and associate a Skills record to it using the MxN field.

Request URL: {{api-domain}}/crm/v6/Employees
Request Method: POST
Sample Input:
{
    "data": [
        {
            "Name": "Patricia",
            "Email": "patricia@mail.com",
            "Position": "Marketing Specialist",
            "Year_of_Experience": 5,
            "Skills": [ //API name of the multi-select lookup field in Employee module
                {
                    "Skills": { //API Name of the lookup field pointing to the Skills module in the linking module
                        "name": "Marketing",
                        "id": "5725767000002149427" //Record ID in the Skills module 
                    }
                },
                {
                    "Skills": {
                        "name": "Social Media Marketing",
                        "id": "5725767000002149476" 
                    }
                }
            ]
        }
    ]
}



How to disassociate an employee & skills relation while updating an Employee record through the Update Records API 

Request URL: {{api-domain}}/crm/v6/Employees
Request Method: PUT

Sample Input:
{
    "data": [
        {
             "id": "7890710000097291",
            "Name": "Patricia",
            "Email": "patricia@mail.com",
            "Position": "Marketing Specialist",
            "Year_of_Experience": 5,
            "Skills": [ 
                {
                    "Skills": { 
                        "name": "Marketing",
                        "_delete": null, //This association will be deleted
                        "id": "5725767000002149427" //Skills record id
                    }
                }
            ]
        }
    ]
}

Sending _delete:null will cause delinking of the association.

How to associate an employee's skills via "Linking Module"

You can associate the relationship between Employees and Skills module by creating records in the Linking module (EmpXSkills). Use the API names for the corresponding lookup fields, Employee (API Name: Employees) and Skills (API Name: Skills) in the input body.

Request URL: {{api-domain}}/crm/v6/EmpXSkills
Request Method: POST

Sample Input
{
   "data": [
        {
            "Name": "Patricia",
            "Employees": { 
                "id": "5725767000002161001" //unique record ID in the Employees module. GET your ID here
            },
             "Skills": { 
                "id": "5725767000002149476" //unique record ID in the Skills module. GET your ID here
            }
        }
    ]
}


Sample Response


The id in the above response is the Primary Key ID of an Employee-Skill association record in the linking module. This ID can later be used to do specific operations like association update or deletion via API.

How to disassociate an employee & skills relationship via "Linking Module"
Use the Delete Records API to delete the record which corresponds to the specific relation between Employee and Skills module in the EmpXSkills module. You can get the record ID for the specific association using the Get Records API for the linking module. 
Use the Delete Record API to delete the specific record, thereby deleting the specific association between the Employee and Skills record. Please note that only the association is removed, and not the individual records. 
Sample Request and Response



When to use create/update operation in Employees/EmpXSkills module?

Use "Employees" module: When you want to create/update records in the Employees module, and associate the record with a Skills record in a single API call.
Use "EmpXSkills" module: When you want to associate/disassociate the relationship between existing Employees and Skills records. 

Retrieve data via COQL API and Bulk Read API

There may be situations where you need to fetch records based upon certain conditions.
For example, Zylker's HR team wants to retrieve the list of employees having more than 4 years of experience and are experts in Social media marketing. In this case, they can use Zoho CRM's COQL API or Bulk Read API. Let's see how to achieve this.

Retrieving MxN data via COQL API

We know that both the Employees and Skills modules' association data is maintained in the linking module. In order to retrieve data from the linking module, query using the API name of the lookup fields in the linking module.

Request URL: {{api-domain}}/crm/v6/coql
Request Method: POST

Sample Input:

{
    "select_query" : "select Employees.Name as employee_name, Employees.Year_of_Experience as employee_experience, Skills.Name as skill_name from EmpXSkills where Employees.Year_of_Experience > 4 and Skills.Name like '%Social%'"
}


From the SQL perspective, above COQL can be interpreted as
select emp.Name as employee_name, emp.Year_of_Experience as employee_experience, skill.Name as skill_name from EmpXSkills left join Employees as emp on EmpXSkills.Employees = emp.id left join Skills as ski on EmpXSkills.Skills = ski.id where emp.Year_of_Experience > 4 and ski.Name like '%Social%'

Sample Response


Retrieving MxN data via Bulk Read API

Bulk Read API allows you to fetch a large set of data i.e., you can fetch a maximum of 200,000 records in a single API call. 
To export linking module records, use its API name.

Request Method: POST
Sample input to export linking module's records:
{
    "callback": {
        "method": "post"
    },
    "query": {
        "module": {
            "api_name": "EmpXSkills" //API name of the linking module
        },
        "file_type": "csv"
    }
}

Export linking module records that meet the specified criteria
To export linking module's records based on the given criteria above (similar to the COQL API).
{
    "callback": {
        "method": "post"
    },
    "query": {
        "module": {
            "api_name": "EmpXSkills"
        },
        "fields": [
            "Employees.Name",
            "Employees.Year_of_Experience",
            "Skills.Name"
        ],
        "criteria": {
            "group": [
                {
                    "field": {
                        "api_name": "Employees.Year_of_Experience" 
                    },
                    "comparator": "greater_than",
                    "value": "4"
                },
                {
                    "field": {
                        "api_name": "Skills.Name"
                    },
                    "comparator": "contains",
                    "value": "Social"
                }
            ],
            "group_operator": "AND"
        }
    }
}


As the API is an asynchronous API, the response will not be available instantly; the bulk read job is scheduled, and the status can be checked. Once the job is completed, you will be notified in the callback URL. The records are available in a downloadable CSV file or ICS file (for events). See the Bulk Read API document to know how to view the status of the scheduled job and download the file, along with more sample requests and responses.

We trust that this post meets your needs and is helpful. Let us know your thoughts in the comment section or reach out to us at support@zohocrm.com
Stay tuned for more insights in our upcoming Kaizen posts!

------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------
Cheers!



    Access your files securely from anywhere


            Zoho Developer Community





                                      • Desk Community Learning Series


                                      • Digest


                                      • Functions


                                      • Meetups


                                      • Kbase


                                      • Resources


                                      • Glossary


                                      • Desk Marketplace


                                      • MVP Corner


                                      • Word of the Day


                                      • Ask the Experts



                                          Zoho Marketing Automation


                                                  Manage your brands on social media



                                                        Zoho TeamInbox Resources

                                                          Zoho DataPrep Resources



                                                            Zoho CRM Plus Resources

                                                              Zoho Books Resources


                                                                Zoho Subscriptions Resources

                                                                  Zoho Projects Resources


                                                                    Zoho Sprints Resources


                                                                      Qntrl Resources


                                                                        Zoho Creator Resources



                                                                            Zoho CRM Resources

                                                                            • CRM Community Learning Series

                                                                              CRM Community Learning Series


                                                                            • Kaizen

                                                                              Kaizen

                                                                            • Functions

                                                                              Functions

                                                                            • Meetups

                                                                              Meetups

                                                                            • Kbase

                                                                              Kbase

                                                                            • Resources

                                                                              Resources

                                                                            • Digest

                                                                              Digest

                                                                            • CRM Marketplace

                                                                              CRM Marketplace

                                                                            • MVP Corner

                                                                              MVP Corner





                                                                                Design. Discuss. Deliver.

                                                                                Create visually engaging stories with Zoho Show.

                                                                                Get Started Now


                                                                                  Zoho Show Resources


                                                                                    Zoho Writer Writer

                                                                                    Get Started. Write Away!

                                                                                    Writer is a powerful online word processor, designed for collaborative work.

                                                                                      Zoho CRM コンテンツ






                                                                                        Nederlandse Hulpbronnen


                                                                                            ご検討中の方





                                                                                                  • Recent Topics

                                                                                                  • Agents can manage the Tasks on the go, now with Zoho Desk mobile app

                                                                                                     Hello, Everyone!    We are elated to announce one of our most asked for features 'Tasks' in the Zoho Desk app.  Agents can now create and associate tasks with a ticket and the tasks will be listed within the corresponding tickets.   Steps to access the tasks from the app:    1. Go to a particular ticket in the app. 2. Click the Tasks icon in the 'Related Information' section.  3. List of all the tasks will be displayed.    Refer to the screenshots (Android & iOS) attached below for your better understanding:
                                                                                                  • Accountant

                                                                                                    Hi if I have a commercial company with multiple sales outlets, sales representatives and multi currency, what is the best subscription you offer? thanks.
                                                                                                  • Sign

                                                                                                    My name is Dolores Houghton. I signed up for sign package by mistake. I can’t use the program and I want my money back. I have been sent various instructions on how to delete and ask for a refund. Nothing works. I am not able to get into settings for
                                                                                                  • Sync CRM inventory data with Zoho Books

                                                                                                    I just switched everything over to ZoHo books, but I am trying to find out why the CRM Estimates, Invoices, and Sales Orders created in ZoHo CRM are not then duplicated in ZoHo Books? I had Quickbooks before, and had to do everything twice, I thought
                                                                                                  • Zoho CRM and Books integration (related list) column customization

                                                                                                    I was wondering if it's possible to add more cloumns (more informations) inside the related list that we get when we enable the integration. As you see we would like to be able to add more information on the invoice (or the same for PO in vendor).
                                                                                                  • Adding Client VAT and BRN in our Invoice

                                                                                                    Hi, Following request from our clients, we need to add their respective VAT and BRN in the invoice that we issue. Could you please let us know if this is something that we can do?
                                                                                                  • Zoho Analytics - Level on level queries

                                                                                                    I am facing a limitation of having too many level on level queries however some of my queries are complex and rely on multiple joins to get my desired output. How can I bypass this limitation as this is hindering my report creation.
                                                                                                  • Manipulate the Date Time field using deluge

                                                                                                    To update the DateTime field using deluge. CurrentVar = zoho.currenttime; TimeVar = zoho.currentdate + " 10:00:00"; if(CurrentVar > TimeVar.todatetime()) { CurrentNew = zoho.currenttime.toTime("yyyy-MM-dd'T'HH:mm:ss").toString("yyyy-MM-dd'T'HH:mm:ss+04:00");
                                                                                                  • Support streaming display of long texts in zobot chats (usefull for chatgpt / openAI and any other AI )

                                                                                                    Hello, I was able to test the new features you offer to connect chatgpt or openAI assistant with built-in feature or custom code. This is great but the chat seems very slow and laggy because you don't use streaming api from openAI, so the chat has to
                                                                                                  • Configure Notes Title for Blueprint Transition

                                                                                                    It'd be very helpful to be able to configure note titles on blueprint transitions when requiring notes. This would help tie back the history of notes to the blueprint actions. We have some approval processes in our blueprint and require notes for the
                                                                                                  • Website not publishing

                                                                                                    My website with Zoho (domain purchased on Zoho) - GilmoreGirlsGetaway.com - has been active for a few months now with no problems. I went to change the template and make modifications today, but as soon as I click "Publish" it says "Error occurred while publishing - contact support". The website preview looks fine, it just won't update. Thanks, Laura
                                                                                                  • ZDC Hackathon 2024 Category-wise Winners – Zoho CRM Client Script

                                                                                                    Hey everyone! After rigorous evaluation by our 14 expert judges, we’re beyond excited to announce that two incredible teams have won the Zoho CRM Client Script – Product Category award for their outstanding innovations! Team 1: Marcin Duchnowski Team
                                                                                                  • ZDC Hackathon 2024 Category-wise Winners – Zoho Creator

                                                                                                    Hey everyone! After rigorous evaluation by our 14 expert judges, we’re beyond excited to announce that two incredible teams have won the Zoho Creator – Product Category award for their outstanding innovations! Team 1: Wonderboy Thandanani MthiyaneTeam
                                                                                                  • ZDC Hackathon 2024 Category-wise Winners – Zoho CRM Custom Function

                                                                                                    Hey everyone! After rigorous evaluation by our 14 expert judges, we’re beyond excited to announce that two incredible teams have won the Zoho CRM Custom Function – Product Category award for their outstanding innovations! Team 1: Onur Gulay Team 2: Yonathan
                                                                                                  • ZDC Hackathon 2024 Category-wise Winners – Catalyst

                                                                                                    Hey everyone! After rigorous evaluation by our 14 expert judges, we’re beyond excited to announce that two incredible teams have won the Catalyst – Product Category award for their outstanding innovations! Team 1: Raghavan P, Santhosh Kumar K, and Jayabalan
                                                                                                  • ZDC Hackathon 2024 Category-wise Winners – Extensions

                                                                                                    Hey everyone! After rigorous evaluation by our 14 expert judges, we’re beyond excited to announce that two incredible teams have won the Extensions – Product Category award for their outstanding innovations! Team 1: Puneet Chandhok, Parv Kumra and Akriti
                                                                                                  • ZDC Hackathon 2024 Category-wise Winners – Zoho SalesIQ Zobot

                                                                                                    Hey everyone! After rigorous evaluation by our 14 expert judges, we’re beyond excited to announce that two incredible teams have won the Zoho SalesIQ Zobot – Product Category award for their outstanding innovations! Team 1: Naveenkumar M, Tulasidhasan
                                                                                                  • Announcing the Zohotshots of the ZDC Hackathon 2024

                                                                                                    Hey everyone! After 46 days of innovation, collaboration, and intense competition, the first-ever Zoho Developer Community (ZDC) Hackathon has officially concluded! 🎉 With 1079 participants, 797 teams, and representation from 45 countries across 6 continents,
                                                                                                  • Retrieve separate records from multiselect lookup field

                                                                                                    Hi, I know there are many post on this one, but I just don't get it. I have a multiselect look-up field named Delivery containing 3 different informations like this : Montreal - Tuesday - 3 to 4 pm I need to do an IF script based on the first item in
                                                                                                  • Cannot set Subform Multiline field to read-only using Client Script

                                                                                                    I am using client script to set different subform fields as read-only It works for Single Line Fields, but when I try to set a Multiline field as Read-only it doesn't work var subform = ZDK.Page.getSubform("Subform_1"); var item_Code_old = subform.getField('Item_Code_Old').setReadOnly(true);
                                                                                                  • Round robin not processing backlog tickets

                                                                                                    We set up a round-robin for one of our departments which initially worked, but something seems to have broken during the 'tweaking' process as it will no longer assign backlogged tickets of any kind. (I've included images of the settings.) Based on the
                                                                                                  • Deluge script that creates a popup with a dropdown list of choices

                                                                                                    Hi, In an order form, when a portal user choose a delivery day, another field is automatically filled with a delivery location, and that field is not linked with a lookup. I have now one day of the week that has 2 delivery locations. I do not want to
                                                                                                  • Schedule workflows to run on business days only (not weekends)

                                                                                                    Is there any way in Bigin to set workflow automation emails to run only on business days (Monday-Friday) and not weekends? It will be strange for my customer to receive an email from us on a Sunday for example, if my workflow is set to send an email in
                                                                                                  • A way to view the sales of leads conversion that were successful

                                                                                                    Hi there, I have a question about this analytic component that can be selected in the dashboard. Currently it shows the conversion rate of leads plus how many leads went to deals and how many won deals. I want to be able to view how much sales the lead
                                                                                                  • Lookup Field Values In BulkRead

                                                                                                    I am pulling cases from the Zoho Case module using the BulkRead API. However, I am receiving IDs (random numbers) as field values. I later discovered that if I include column_name.Name in the returned fields, I get the actual value. However, this approach
                                                                                                  • Email alias per task list so these tasks don't get listed under a 'General' task list that we didn't create nor use

                                                                                                    Using an email alias to add tasks is very good for forwarding emails directly into Zoho Projects however everything gets listed under a 'General' task list which is counter-intuitive. It would be good to have an email alias for each task list so we can
                                                                                                  • CRM portal users can now log in using their mobile phone numbers

                                                                                                    Hello everyone! You can now invite portal users using their mobile phone numbers. These portal users will be able to log in using their mobile number and OTP. Templates for these portal-related SMS can be customized as per your needs. This enhancement
                                                                                                  • Menu Bar

                                                                                                    Hi, Please guide how to change menu bar from vertical to horizontal
                                                                                                  • Zoho Signing embedded with iframe is moved out of view when navigating to focus signature on mobile devices

                                                                                                    Dear Zoho team, I'm having difficulty embedding the signing url into a website for users to sign on their phones, it's not working perfectly. The problem occurs after the user accepts and continues to sign, or the user clicks to redirect to any of the
                                                                                                  • Insert information on another form of a Zoho loginuser

                                                                                                    Hello, I have 2 forms that are linked, a customer form, and then a subscription form in which there will be a subscription number that I would like to transfer back in a field of the first form called "current subscription number", How do I write the
                                                                                                  • Confirmation prompt before a custom button action is triggered

                                                                                                    Have you ever created a custom button and just hoped that you/your users are prompted first to confirm the action? Well, Zoho knows this concept. For example, in blueprint, whenever we want to advance to the next state by clicking the transition, it is
                                                                                                  • Canvas View in Zoho Recruit

                                                                                                    Is it possible or would it be possible to have the new 'Canvas View' in Zoho Recruit?
                                                                                                  • Kaizen #78 : How to disable clone record?

                                                                                                    Hello everyone! Welcome back to another interesting Kaizen post. In this post, let us discuss a workaround solution for the use case - How to disable clone record for a user. Requirement Consider that you want to disable the clone option for the Deals
                                                                                                  • Automated Shopify adjustment problem. "An inventory adjustment has been created by the system to set the initial stock from Shopify"

                                                                                                    Has anyone noticed issues since the Shopify Sync has been updated recently? If you sync with Shopify, check to see if there are automated adjustments for old products that keep recurring. We have this problem for 6 SKU's that Zoho is doubling the stock
                                                                                                  • Mass-Delete-Action over API doesn't work because of scope

                                                                                                    Hi all, we're currently trying to mass delete 40000 deals from our CRM, that we have already put into a custom view. I'm not that used to the API, but I managed to authenticate by https://accounts.zoho.com/oauth/v2/token with Postman and going by the
                                                                                                  • Can you be a Learner as well as a Contributor

                                                                                                    If you are the Author or a Contributor, can you also be assigned as a Learner? This is particularly relevant if you need to certify that you have taken the quiz and done the learning yourself!
                                                                                                  • Merge Tickets Directly from Contact Page in Zoho Desk

                                                                                                    Dear Zoho Desk Support Team, We are writing to request a new feature that would allow users to easily merge tickets directly from the contact page in Zoho Desk. Currently, the only option to merge tickets is from the Tickets list view page, which can
                                                                                                  • Important update in Zoho Forms: Enhancements for improved email deliverability

                                                                                                    Hello, form builders! We would like to inform you about some changes we're making in Zoho Forms to ensure the deliverability of your outbound emails. Changes to Gmail policies Gmail has updated its DMARC policy which quarantines emails sent with gmail.com
                                                                                                  • Multiple Vendor SKUs

                                                                                                    One of the big concerns we have with ZOHO Inventory is lack of Vendor Skus like many other inventory software packages offer. Being able to have multiple vendor skus for the same product would be HUGE! It would populate the appropriate vendor Sku for
                                                                                                  • Introducing Booking Pages—an topping for your Calendar Scheduling needs!

                                                                                                    Greetings, We're here with a new topping for Bigin! Let's dive into the details. What does this topping do? Scheduling appointments with customers is one of the most common challenges small businesses face on a daily basis, as it often involves frequent
                                                                                                  • Next Page