Kaizen #26 - Linking module and Multi-select Lookup fields

Kaizen #26 - Linking module and Multi-select Lookup fields

Hello everyone!
Welcome to another post in the Kaizen series!
This week, we will discuss how to add/delete values to a multi-select lookup field through linking modules via API and achieve many-to-many relationships.

Your data in CRM are often inter-related. For example, you may want to associate an account with contact. You can easily achieve this through a lookup field in the Contacts module that looks up to an account in the Accounts module.

As you can see, this is a one-to-many relationship. However, you can select only one value using a lookup field.

Now, consider a scenario where you want to associate the same contact with two accounts. Here, the lookup field is not helpful as it lets you choose only one record.

To establish many-to-many relationships, you must use the multi-select lookup field.

Example Scenario
Problem
Zylker Real Estates manages buying/renting apartments. They have two modules in their CRM—Listings and Leads.

Jack Smith is one of the leads and is interested in looking at three listings (C-807, B-196, and H-786).
Apart from Jack, three other leads—Jane, Jill, and Derek—are all interested in looking at C-807.

When you create a Lead record for Jack Smith, there must be a provision to choose from the three listings he is interested in. Also, the listing C-807 should have four leads associated with it. So there is a need to choose many values from a lookup field. A regular lookup field lets you choose only one value.

Solution
In this case, Zylker Real Estates could create a multi-select lookup field in the Leads module, as shown in the image below.



So, data in both modules would look like below.



Consider Jack Smith requests a negotiation for each listing, and the negotiated rent differs for all three listings. Now, where can this field be stored?
  • It cannot be a field in Jack's record, as there are three different prices based on each house.
  • It cannot be a field in the listing's record either, as other prospects apart from Jack may have offered different negotiations for it.

To manage this diversity, Zoho CRM allows you to create a Linking Module. Each association between two modules (created via a multi-select lookup field) is a record in the linking module. So, when three listings are associated with Jack, three separate records are created in the Linking Module that lets you create separate Negotiated Rent in each record.



Adding values to a multi-select lookup field through an API
When you manipulate records through the API, it is not possible to add values to a multi-select lookup field directly from the module where the multi-select lookup field is present, like how you add values to a lookup field.
Instead, you can create a record in the linking module by passing the values of both the lead and listing's IDs.
Now, let us try to add another Listing (A-101) to the lead Jack Smith.

Details required
  • API name of the Linking module. You can obtain this through the Modules API. The value "linking" of the key "generated_type" indicates that this is a linking module. In our case, it is Leads_vs_Listings.
  • API Names of the lookup fields pointing to the Leads and the Listings module. They are the fields of the Linking module. Here, they are Interested_Leads and Interested_Listings.
  • Record IDs of the records from the two modules that you want to associate with the multi-select lookup field.

Request URL: {{api-domain}}/crm/v2/Leads_vs_Listings
Request Method: POST

Sample Input

{
    "data": [
        {
            "Interested_Leads": {
                "id": "3652397000001970024" //ID of the Lead Jack Smith
            },
            "Interested_Listings": {
                "id": "3652397000001988001" //ID of the Listing A-101
            }
        }
    ]
}
Sample Response

{
    "data": [
        {
            "code": "SUCCESS",
            "details": {
                "Modified_Time": "2020-04-02T18:27:10+05:30",
                "Modified_By": {
                    "name": "Patricia Boyle",
                    "id": "3652397000000186017"
                },
                "Created_Time": "2020-04-02T18:27:10+05:30",
                "id": "3652397000001987014",
                "Created_By": {
                    "name": "Patricia Boyle",
                    "id": "3652397000000186017"
                }
            },
            "message": "record added",
            "status": "success"
        }
    ]
}
In the UI, for the lead Jack Smith



 In the UI, for the listing A-101



In the UI, in the linking module



Deleting/dissociating values from a multi-select lookup field through an API
Deleting the record from the linking module deletes the association between the two modules.
Here, let us delete the association between the lead Jack Smith and the listing A-101. Pass the ID of the record that associates these two in the linking module.

Request URL: {{api-domain}}/crm/v2/Leads_vs_Listings/{{record_id_in_the_linking_module}}
Request Method: DELETE

Sample URL: {{api-domain}}/crm/v2/Leads_vs_Listings/3652397000001987014

Sample Response

{
    "data": [
        {
            "code": "SUCCESS",
            "details": {
                "id": "3652397000001987014"
            },
            "message": "record deleted",
            "status": "success"
        }
    ]
}
In the UI, for the linking module





Fetching the Related Records of a Linking Module
When you view a record's details, you can find a multi-select lookup field as a related list in the associated module. In our case, you can find Listings as a related list in the Leads module, while Leads is a related list in the Listings module.

This related list will also display details of the Linking Module, if you have chosen to create one, as in the below image.



To fetch the related list details from a module, you need
To fetch the related records associated with the Listings module, the request URL must contain the module name, the ID of the record whose related records you want to fetch, and the related list API name.

Let us now fetch the related records associated with the Listing H-786.

Request URL: {{api-domain}}/crm/v2/Listings/3652397000001978027/Leads3
Request Method: GET

Sample Response

{
    "data": [
        {
            "$approval": {
                "delegate": false,
                "approve": false,
                "reject": false,
                "resubmit": false
            },
            "Owner": {
                "name": "Patricia Boyle",
                "id": "3652397000000186017",
                "email": "p.boyle@abc.com"
            },
            "Modified_Time": "2020-04-02T17:54:05+05:30",
            "Email": null,
            "$currency_symbol": "Rs.",
            "Interested_Leads": {
                "name": "Jack Smith",
                "id": "3652397000001970024"
            },
            "Interested_Listings": {
                "name": "H-786",
                "id": "3652397000001978027"
            },
            "Created_Time": "2020-04-02T16:12:27+05:30",
            "$review_process": null,
            "$editable": true,
            "$orchestration": null,
            "Name": "10004",
            "Last_Activity_Time": "2020-04-02T17:54:05+05:30",
            "Modified_By": {
                "name": "Patricia Boyle",
                "id": "3652397000000186017",
                "email": "p.boyle@abc.com"
            },
            "$review": null,
            "$state": "save",
            "$process_flow": false,
            "Negotiated_Rent": "4500",
            "id": "3652397000001980020",
            "Created_By": {
                "name": "Patricia Boyle",
                "id": "3652397000000186017",
                "email": "p.boyle@abc.com"
            },
            "Secondary_Email": null,
            "Email_Opt_Out": false,
            "$approved": true
        }
    ],
    "info": {
        "per_page": 200,
        "count": 1,
        "page": 1,
        "more_records": false
    }
}

In the UI,



We hope you found this post useful. Write to us at support@zohocrm.com if you have any questions, or let us know in the comment section.

Cheers!

    Access your files securely from anywhere

        Zoho Developer Community




                                  Zoho Desk Resources

                                  • Desk Community Learning Series


                                  • Digest


                                  • Functions


                                  • Meetups


                                  • Kbase


                                  • Resources


                                  • Glossary


                                  • Desk Marketplace


                                  • MVP Corner


                                  • Word of the Day



                                      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 Campaigns 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