Extension Pointers - JS SDK Series #8: Use the SearchRecord API in a widget to simplify business operations

Extension Pointers - JS SDK Series #8: Use the SearchRecord API in a widget to simplify business operations

Looking up relevant business information is easier when you have an internal search feature that targets certain keywords or phrases. Often times, this information will be worked with and manipulated to be useful for the current task the searcher is doing, which means that a faster internal search process will lead to better productivity.

The SearchRecord API is used to retrieve records that match your search criteria. It performs a module-level search based on either a phone number, email address, word, or other piece of criteria. It's most helpful to search for text in the fields of data type "string", "phone", or "Email".

In this post, we will look at an example that involves searching for and updating records using the searchRecord and updateRecord APIs. We'll first give the syntax followed by an example scenario.

SearchRecord API

Syntax

ZOHO.CRM.API.searchRecord(config, page, per_page) 

Here, config refers to the configuration object of the 'object' type, page refers to the page number, and per_page refers to the number of records to be generated per page.

Configuration Object

Name
Type
Description
Entity
String
SysRefName (of the module)
Type
String
Allowed values "email|phone|word|criteria"
Query
String
Query string
delay
Boolean
Query string

Note : Please check here for more details and limitations on SearchRecord API.

UpdateRecord API

Syntax

ZOHO.CRM.API.updateRecord(config) 

Here, config refers to the configuration object of the 'object' type.

Configuration Object

Name
Type
Description
Entity
String
SysRefName (of the module)
Trigger
list
The trigger input can be "workflow", "approval", or "blueprint". If the trigger is not mentioned, the workflows, approvals, and blueprints related to the API will get executed. Enter the trigger value as [] to not execute the workflows.

API data
String
The data to be updated is constructed as
updateRecord's API Data parameter.

Let's take a simple scenario where a Zoho CRM user is handling a customer case. They would like to check if a similar problem has already been addressed in another case and if they can use any of those solutions for their own case. In our example, we will see:
  • How the SearchRecord API can help the user find solutions using keywords related to the current case
  • How the Search API returns the description and the solution of cases based on the keywords we enter
  • How the user can update the correct solution to the current case if the relevant solution is found
SearchAPI.js code snippet

Util={};
var EntityIds;
var EntityName;
var inputtext;
var solutiontext;
var solutiondescription;

//Subscribe to the EmbeddedApp onPageLoad event before initializing the widget 
ZOHO.embeddedApp.on("PageLoad",function(data)
{
EntityIds=data.EntityId;
EntityName=data.Entity;

//Search for solutions using input search words
Util.search=function()
{
inputtext=document.getElementById("inputword").value;

//Searches across the cases module for the input text entered 
ZOHO.CRM.API.searchRecord({Entity:"Cases",Type:"word",Query:inputtext})
.then(function(data){
console.log(data);
rec=data.data;
$('#solutionlist').empty();

//Looping through the solutions
for (i = 0; i < rec.length; i++) 
{

/*populating the solution list list with the solutions and description of all the cases associated with the input text provided*/
solutionsid=rec[i].id;
solutionname=rec[i].Solution;
solutiondescription=rec[i].Description;
solutionsname=rec[i].Description+"-"+rec[i].Solution;

/* Add the description-solution to the list only if the description or solution field is not null for the cases searched based on the input text */
if(solutionname!=null && solutiondescription!=null)
{
var solutionlist = document.getElementById("solutionlist");
var option = document.createElement("OPTION");
option.innerHTML = solutionsname;
option.value = solutionsid;
solutionlist.appendChild(option);
}
}
})
}

//Updates the solution to the solution field of the current case and changes the case status to closed 
Util.update=function()
{
solutiontext=document.getElementById("solutiontext").value;

var config={
Entity:"Cases",
APIData:{
"id": EntityIds[0],
"Solution":solutiontext,
"Status":"Closed"
},
Trigger:[]
}
ZOHO.CRM.API.updateRecord(config)
.then(function(data){
console.log(data)
})
}

// Closes the widget popup
Util.cancel=function()
{
ZOHO.CRM.UI.Popup.close()
.then(function(data){
console.log(data)
})
}
})

In the above code snippet, the input text keyed in is retrieved and passed as the Query parameter to the searchRecord API. The type parameter is passed as 'word', and the Entity parameter as 'Cases'. This searches across the Cases module for the input text and returns all the cases with the word present.

From the retrieved cases, the descriptions and solutions are fetched and populated into a select list. The user can have a look at the solutions and choose one if it resolves the current case issue.

The chosen solution is populated in the 'Enter solution here' textbox. The user can choose to edit the solution further according to their needs in the textbox and then click the 'Update Solution and close Case' button.

The updateRecord API will then update the solution entered to the solution field of the current case, and will change the status of the case to "Closed".

Sample Widget:

The user handles a case about a hardware issue. In the widget, they enter the word 'hardware' in the input field because it is a relevant word associated with the current case.



When the user clicks the 'Check for solutions' button, the searchRecord API returns all the descriptions and solutions involving 'hardware'. The user chooses a solution if it is relevant and makes further edits relevant to their case in the solution textbox. The 'Update Solution and close Case' button will update the solution to the solution field of the current case and close the ticket.



This was just an example, but there are many similar ways you can use the SearchRecord API to suit your specific business needs.

We hope you found this information useful. Keep following this space for more info!


SEE ALSO


    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