Extension pointers - JS SDK Series #1: Learn how to invoke a REST API function from a widget using the execute method

Extension pointers - JS SDK Series #1: Learn how to invoke a REST API function from a widget using the execute method

Software development kits (SDK) are sets of tools that are useful when building applications on a platform. They wrap up APIs in the form of libraries, and include sample code, utilities, and documentation that guides you in building your applications. 

In our earlier posts we discussed building embeddable widgets for Zoho CRM. These widgets help to seamlessly integrate Zoho CRM with other applications and provide contextual information along with the application's data. Zoho CRM provides the JS SDK bundled with the necessary APIs and utilities to build these widgets using JavaScript. It serves as a mode of interaction between the JavaScript code and Zoho CRM. Through this JS SDK series of extension pointers, we aim to help you gain a deeper understanding of JS SDKs, and how to build efficient extensions.

The JS SDK bundle of Zoho CRM APIs is significant in helping you develop powerful widgets using JavaScript.

The Zoho CRM JS SDK, includes most of the APIs that help you operate with Zoho CRM data. It also includes event listeners that are useful for registering your application's events. The JS SDK also provides support to manage your widget's UI, handle configurations and connections with third party applications, and more. We're going to look at the different options available in the JS SDK, one at a time, throughout this series.

In this post, let's take a look at the ZOHO.CRM.FUNCTIONS.execute() function, its benefits,and how it can be incorporated while building extensions. It's designed to help you invoke and execute a custom function from a widget. Only a standalone REST API function can be invoked from your widget. A few major pointers regarding this API are:

➤ The ZOHO.CRM.FUNCTIONS.execute() function lets you invoke only the REST API function from a widget
➤ It requires that you input the API name of the function along with the constructed set of request data

Syntax

ZOHO.CRM.FUNCTIONS.execute(func_name, req_data)

Here, 'func_name' is the API name of the REST API function. 'req_data' is the constructed argument set that needs to be passed to the function.

Example

var func_name = "sample_function";
var req_data ={
"arguments": JSON.stringify({
"Company" : "Zoho",
"Email" : "saxxxx@xxxxx@.com",
})
};
ZOHO.CRM.FUNCTIONS.execute(func_name, req_data)
.then(function(data){
console.log("REST API function invoked from widget."+data);
})

Here, 'sample_function' is the API name of the REST API function. The arguments, namely 'Company' and 'Email',are constructed and passed as the 'req_data' parameter to the ZOHO.CRM.FUNCTIONS.execute() function.

Now let's see how the execute function can be incorporated while creating widgets to build an extension.
Note: Widgets are embeddable GUI components that help extend Zoho CRM's functionality. To get detailed information on widgets and how they work,please refer here.

To demonstrate the use of ZOHO.CRM.FUNCTIONS.execute(), let's assume a scenario in Zoho CRM involving raised product issues or concerns are registered as Cases by an organization. In general, cases originate through different modes, for example through phone, web, or email. Let's build a widget with a customized UI that allows a user to key in certain values pertaining to the 'Cases' module. This widget will fetch the necessary values and pass them to a REST API function that will create a record in the Cases module. This could help the support user on a phone call with the client to quickly build a case by filling out only the specific details.

Code snippet:
sdkwidget.js

Util={};
//assigning api name of REST API function to 'func_name' parameter of the execute function
var func_name="jssdkextension__executesdkfunction";
Util.check=function()
{
console.log("inside function");
//fetching the values provided in the UI
var subject = document.getElementById("subject").value;
var phoneno = document.getElementById("phnumber").value;
var email = document.getElementById("email").value;
var x = document.getElementById("cases").selectedIndex;
var x1 = document.getElementById("cases").options;
var cases=x1[x].text;
var y = document.getElementById("status").selectedIndex;
var y1 = document.getElementById("status").options;
var status=y1[y].text;
//constructing the 'req_data' parameter with the values fed by the user through the UI
var req_data ={
"arguments": JSON.stringify({
"sub" : subject,  
"phone" : phoneno,
"cases" : cases,
"status" : status,
"email" : email
})
};
//Invoking the execute function to execute the REST API function
ZOHO.CRM.FUNCTIONS.execute(func_name, req_data).then(function(data){
var resp=JSON.stringify(data);
})
}


executesdkfunction Rest API function

//retrieving the parameters of the request
params = crmAPIRequest.get("params");
//retrieving the set of values from 'arguments' passed as 'req_data' in the javascript code
args = params.get("arguments");
data = Map();
sub = args.get("sub");
phone = args.get("phone");
caseorigin = args.get("cases");
status = args.get("status");
email = args.get("email");
data.putAll({"Subject":sub,"Phone":phone,"Case_Origin":caseorigin,"Status":status,"Email":email});
//creating a new record in the Cases module
resp = zoho.crm.createRecord("Cases",data);
}
return args;

The highlighted text in the code snippet above is used to fetch the values provided by the user through the variable 'arguments' that is passed as the 'req_data' parameter to the REST API function.

Note: You can obtain the API name of the function from the sandbox URL or production URL obtained while using the option 'Invoke as REST API' in the script editor function.



Sample Output of Widget Screen



A new record is inserted in the Cases module according to the inputs provided.



Hope you found this information useful! For more about JS SDKs, keep following this space.

SEE ALSO:



<<Previous                                                                                                                                                    Next>>


    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





                                                          Manage your brands on social media



                                                                Zoho TeamInbox 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

                                                                                            Get Started. Write Away!

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

                                                                                              Zoho CRM コンテンツ






                                                                                                Nederlandse Hulpbronnen


                                                                                                    ご検討中の方




                                                                                                          • Recent Topics

                                                                                                          • How to export all line-item descriptions for a specific item in Zoho Books?

                                                                                                            I am trying to audit a specific item (“Item X”) that has been invoiced multiple times with different line-level descriptions. Here’s the situation: I am using Zoho Books (Professional). Each invoice may contain the same item but with different descriptions
                                                                                                          • List of hidden features

                                                                                                            Hi Friends, I had another support chat today and low and behold the feature that I wanted just simply needed to be "enabled". I thought I'd share, and maybe see if others had some similar experiences. 1. This one is from 5 ish years ago. I asked if there
                                                                                                          • How to change a BAS that has been filed

                                                                                                            I have discovered that a group of expense transactions were accidentally placed in a asset account rather than an expense account. As a result I need to adjust the transaction and consequently most of my BAS to correct the error. Because the BAS have
                                                                                                          • Standard Payment Term is not pulled from account to quotation

                                                                                                            Hey Team There seems to be something off. I do have "Net 30" as my default payment term in Zoho Books for my customers. If, from the customer overview or quote section, I create a new Quotation, the payment terms field stays blank and doesn't get the
                                                                                                          • How to Export PDF with a custom Template

                                                                                                            I need to export Sales Order with a Custom Template I have created How can I do it? I see an API to export the PDF but how can I choose which template to choose to generate the PDF
                                                                                                          • Create custom rollup summary fields in Zoho CRM

                                                                                                            Hello everyone, In Zoho CRM, rollup summary fields have been essential tools for summarizing data across related records and enabling users to gain quick insights without having to jump across modules. Previously, only predefined summary functions were
                                                                                                          • Associate email with a potential or project.

                                                                                                            I have a pivotal requirement to associate emails from various suppliers (contacts) with different potentials or projects, on an email by email basis as they come in. This question appears to have been raised before but I cannot find a definitive yes "it can be done". Could anyone please tell me, yes or no.  If the later I can stop wasting time and look at alternative crm systems. I would love not to have to do this. Thanks in advance.
                                                                                                          • MTA - BAD IP reputation by outlook/hotmail

                                                                                                            Messages to Microsoft email servers are bouncing back due to poor reputation. Message: 4.7.650 The mail server [136.143.188.206] has been temporarily rate limited due to IP reputation. For e-mail delivery information see https://postmaster.live.com (S775)
                                                                                                          • Function with Search Records was working until a few weeks ago, around when "Connected Records" was released

                                                                                                            I have a custom function that has been running for nearly a year now, which suddenly stopped working around the time Zoho released the "Connected Records" update. The function is no longer finding the record using the searchRecords function. I've changed
                                                                                                          • Is CRM On Premise available

                                                                                                            Hi Zoho team, Can you please let me know that CRM Zoho is available for On Premise as well? Thanks, Devashish
                                                                                                          • How to sync from Zoho Projects into an existing Sprint in Zoho Sprints?

                                                                                                            Hi I have managed to integrate Zoho Projects with Zoho Sprints and I can see that the integration works as a project was created in Zoho Sprints. But, what I would like to do is to sync into an existing Zoho Sprints project. Is there a way to make that
                                                                                                          • Online Assessment or any aptitude test

                                                                                                            This video is really helpful! I have one question — if I share an assessment form link (through email or with the application form on my career page), how does Zoho Recruit evaluate it? Can a candidate use Google or external help while taking the test,
                                                                                                          • How Zoho Desk contributes to the art of savings

                                                                                                            Remember the first time your grandmother gave you cash for a birthday or New Year's gift, Christmas gift, or any special day? You probably tucked that money safely into a piggy bank, waiting for the day you could buy something precious or something you
                                                                                                          • Editing the Ticket Properties column

                                                                                                            This is going to sound like a dumb question, but I cannot figure out how to configure/edit the sections (and their fields) in this column: For example, we have a custom "Resolution" field, which parked itself in the "Ticket Information" section of this
                                                                                                          • Need a way to secure Prefill URLs in Zoho Forms (hide or encrypt prefilled values)

                                                                                                            Hi everyone, I often use Zoho Forms with prefilled URLs to simplify the user experience — for example: https://forms.zohopublic.com/.../form?Name=David&Amount=300 However, the problem is that all prefilled values are visible and editable in the link.
                                                                                                          • Incoming Threads Report

                                                                                                            From data to decisions: A deep dive into ticketing system reports Customers raise questions and issues through multiple channels, such as email, chat, or tickets. To monitor the number of queries received on a specific day from each channel, leads can
                                                                                                          • Conditional layouts - support for multi-select picklists

                                                                                                            Hi, The documentation for conditional layouts says the following: "Layout Rules cannot be used on the following field types: Auto Number Lookup Multi Select Lookup User Lookup Formula File Upload Multi Line" I have a custom module with a multi-pick list
                                                                                                          • How to apply customized Zoho Crm Home Page to all users?

                                                                                                            I have tried to study manuals and play with Zoho CRM but haven't found a way how to apply customized Zoho CRM Home Page as a (default) home page for other CRM users.. How that can be done, if possible? - kipi Moderation Update: Currently, each user has
                                                                                                          • Cloudflare Turnstile is now available in Zoho Forms!

                                                                                                            Hello form builders! We have added a new layer of protection to help you keep your forms free from bots. Instead of forcing users to prove they are human, Cloudflare Turnstile quietly checks browser signals in the background. Your real users glide through,
                                                                                                          • Power of Automation :: Unique Task & Issue Prefix Format and Sequencing Rule

                                                                                                            Hello Everyone, A custom function is a software code that can be used to automate a process and this allows you to automate a notification, call a webhook, or perform logic immediately after a workflow rule is triggered. This feature helps to automate
                                                                                                          • 【Zoho CRM】キャンバス機能のアップデート

                                                                                                            ユーザーの皆さま、こんにちは。コミュニティチームの藤澤です。 今回は「Zoho CRM アップデート情報」の中から、キャンバス機能のアップデートをご紹介します。 目次 グリッドについて フォーム表示のタブについて 1. グリッドについて ビジュアルデザインは細部の調整に手間がかかりますが、キャンバスのグリッドを使えば要素を整理し、バランスよく配置できます。 画像やデータなどの要素をグループ化せずに簡単に配置できます。 余白を調整することで、要素間の視覚的なバランスを保つのに役立ちます。 「表示切り替え基準の幅」を設定すると、デザインをレスポンシブに調整できます。
                                                                                                          • Deleting unwanted ticket replies

                                                                                                            Hello, In a Zoho Desk Ticket thread, sometimes one of the recipients has auto-reply activated. This creates a new message in the Ticket thread that not only pollutes the thread, but most importantly cannot be replied properly because usually auto-reply e-mails don't do "reply all", so the other recipients are not included. I want to delete such a message in the Ticket thread. I searched the help of Zoho Desk, but only found a way to mark as Spam (https://help.zoho.com/portal/kb/articles/marking-support-tickets-as-spam)
                                                                                                          • Issue: Ticket Export Does Not Include Ticket Threads

                                                                                                            Dear Zoho Desk Support Team, I hope you’re doing well. I wanted to bring to your attention that the current ticket export feature in Zoho Desk does not seem to include the ticket threads or conversation history. When exporting tickets, only the summary
                                                                                                          • Ability to Set Client Name During Portal Invitation

                                                                                                            Hi Zoho Team, We would like to suggest an important enhancement to the Zoho Creator Client Portal functionality. Zoho Creator recently introduced the option to set a client’s display name in the Client Portal settings, which is very helpful for creating
                                                                                                          • スマホでキャンペンメールを見ると正しく表示されない

                                                                                                            キャンペーンのメール(HTML)を作成しましたが、スマホ表示に切り替えると正しく表示されません(添付参照)過去に作成したキャンペーンでは特に意識してませんでしたが、問題なく表示されていたようです。うまく表示される場合とされない場合の違いは何でしょうか?
                                                                                                          • 136.143.188.51 blocked by spamcop

                                                                                                            Zoho mailserver seems to be blocked by spamcop. Cant send mail to my customer. Not sure what to do.
                                                                                                          • Zoho Calendar Integrated Into CRM?

                                                                                                            I've searched around the forums but couldn't find anything addressing this . . .  Is there a plan to integrate Zoho's stand alone calendar solution into Zoho CRM?  The CRM calendar does an OK job but is very basic and the Zoho calendar is great, but I've only figured out to subscribe to my CRM calendar within ZCalendar - there is no 2-way sync. My preferred solution would be for ZCal to become the default calendar/event solution within Z CRM. Is this on the roadmap? Thanks
                                                                                                          • Can I Create Different Page Layouts Based on a Specified Module Pick List Field

                                                                                                            I am trying to work out how to create different page layouts based on a specified module pick list field value, like the Salesforce feature where you can define multiple record types and then create custom page layouts for each record type. This is a super important feature as for almost all the modules we are using (Leads, Potentials, Accounts) we need to be able only show fields relevant to the record type. E.g. We need a very different page layout for a consumer lead Vs a commercial lead, same
                                                                                                          • Scheduling Tasks in Relation to Project End Date

                                                                                                            I use Zoho project  to help manage tasks that relate to a number of specific business events that take place.  I would like to be able to have my project end date be the date of the event and then work "back" from that date to say...   Add a task 2 weeks before the project end date to remind me to XYZ.  Does anyone know if there is a way to base task timings back from a project due date rather than a project start date?
                                                                                                          • What formula to use in computing total hrs and decimal hrss

                                                                                                            So , my data includes log im column , 2 breaks with 2 columns that says back and lunch and 1 column that says back and logged out. What formula should i use to be able to automatically have my total hours as I input time in each column? Thankyou
                                                                                                          • Notes of Tasks in Zoho CRM

                                                                                                            Hello, Is there a way to filter the Notes that appear on a Task to only show the notes related to that specific Task and not display all the Notes of the objects related to that Task (Accounts, Contacts, Deal, etc). In essence, our team struggles to understand
                                                                                                          • Passing the CRM

                                                                                                            Hi, I am hoping someone can help. I have a zoho form that has a CRM lookup field. I was hoping to send this to my publicly to clients via a text message and the form then attaches the signed form back to the custom module. This work absolutely fine when
                                                                                                          • How to next stage blueprint in Zoho Creator

                                                                                                            Hello, I have question, its possible to next stage blueprint? in case, Start - (first stage) Leader 1 (with condition 1) - (second stage) Leader 2 (with condition 2) - (third stage) Leader 3 (with condition 3) - (fourth stage) After first stage, i want
                                                                                                          • Feature Request: Email Follow-Up Sequences Similar to Zoho CRM

                                                                                                            I’m wondering if Zoho Recruit is planning to introduce a feature similar to the Email Automation – Follow-Up Sequences that is available in Zoho CRM. In CRM, this allows users to send a series of timed follow-up emails triggered by specific actions (for
                                                                                                          • Currency limitation when integrating Zoho CRM & Zoho Books

                                                                                                            Brief Video of Problem: https://www.loom.com/share/d61d1d07d0904e149d80c1901a22418e. Background ·       Our business is based in Australia and we have to have Zoho Books in AUD to comply with tax and reporting regulations in Australia. ·       We sell
                                                                                                          • Multi-select Lookup does not have Advanced filter options in CRM

                                                                                                            With much fanfare Zoho announced the advanced filter options for CRM lookup fields which was a nice addition. This feature is not available for Multi-Select lookup fields. Will it be rolled out in the next 3-6 months, considering the standard lookup filter
                                                                                                          • Experience effortless record management in CRM For Everyone with the all-new Grid View!

                                                                                                            Hello Everyone, Hope you are well! As part of our ongoing series of feature announcements for Zoho CRM For Everyone, we’re excited to bring you another type of module view : Grid View. In addition to Kanban view, List view, Canvas view, Chart view and
                                                                                                          • Unable to copy into a new document

                                                                                                            Whe I create a new Writer doc and attemp to copy and past I get this message. The only way to copy into a document is I duplicate an existing document, erase the text and save it under a different name and then paste the information. Not ideal. Can you
                                                                                                          • Kaizen #157: Flyouts in Client Script

                                                                                                            Hello everyone! Welcome back to another exciting edition of our Kaizen series, where we explore fresh insights and innovative ideas to help you discover more and expand your knowledge!In this post, we'll walk through how to display Flyouts in Client Script
                                                                                                          • Customize User Invites with Invitation Templates

                                                                                                            Invitation Templates help streamline the invitation process by allowing users to create customized email formats instead of sending a one-size-fits-all email. Different invitation templates can be created for portal users and client users to align with
                                                                                                          • Next Page