Welcome to Portal

?Unknown\pull-down

Welcome to Zoho Cares

Bienvenido a Soporte de Zoho

Search our knowledge base, ask the community or submit a request.

JS API for Widgets

Notes
This help page is for users in Creator 6. If you are in the older version (Creator 5), click here. Know your Creator version.

1. JS API within Widget

Zoho Creator provides JS API tasks that allow you to perform CRUD operations from within the widgets inserted in an application's page component. They also let you add and manipulate data in other applications in the same Creator account. In other words, these tasks are a wrapper to the Creator REST APIs. The success of the API call to perform a task in an application depends on the permissions provided for the users who access the widget in the target application.
The two JS API versions available are:
V1 - Based on REST API V2
V2 - Based on REST API V2.1 (Recommended)

Example - Say you want to create a uniquely customized form of the feedback matrix review type. This can be achieved by building it as a widget and inserting it in your page. Since this form is situated inside the widget, you will need to perform JS API tasks if you want to manipulate application data.

2. Use Cases

Add and Update Records in the Same Application - Say you've inserted a timer widget in a Project Management application. When an employee starts working on a project, they click the Start button in the widget. This adds a record to the Project Timeline form. When the employee completes the project and clicks the Finish Project button, the same record is updated with the end timeline. This is achieved using the Add Records and Update Records JS API tasks respectively.

3. JS API Configuration

To write the JS API tasks within your widget, you need to perform the following configurations.
STEP 1 : To Be Done in Widget ZIP's HTML File
Include the CDN URL given below by linking it in the script tag of the widget's HTML file. This HTML file will be created automatically when you create a widget ZIP.
  1. <script src="CDN URL"></script>
Notes
Note :
  1. The tasks that can be performed from within the widget are limited to the ones pertaining to a specific version. For example, say you want to execute the JS API V2 Get Records task from within a widget. The records will only be fetched if you've provided the CDN URL pertaining to V2 in the widget's HTML file.

STEP 2 : To be Done in Widget ZIP's JS File
You will have created a JS file inside your widget ZIP to include interactive elements. Use block to write the logic for the JS API tasks in the same file.
Notes
Requirement for JS API V1:
For V1, you should initialize the SDK present in the CDN URL before writing logic for the JS API tasks. Use the below method in the widget ZIP's JS file:
  1. ZOHO.CREATOR.init()
  2.         .then(function(data) {
  3.           //Code goes here
  4.         });

4. JS API Tasks

The JS API V2 tasks you can perform from within the widgets are:
1. Data APIs
  1. Get Record by ID
  2. Get Records
  3. Get Record Count
  4. Update Record by ID
  5. Update Records
  6. Delete Record by ID
  7. Delete Records
 2. Publish APIs
  1. Add Records
  2. Get Record by ID
  3. Get Records 
 3. File APIs
  1. Upload File
  2. Read File
4. Meta APIs
  1. Get Fields
  2. Get Forms
  3. Get Reports
  4. Get Pages
  5. Get Sections
  6. Get Applications
  7. Get Applications by Workspace
5. Util APIs
  1. Set Image Data
  2. Navigate Parent URL
  3. Get Init Params
  4. Get Query Params
  5. Get Widget Params
Info
Only few of these tasks are supported in V1. Refer to JS API V1 Overview to learn more about the tasks that can be performed in V1.

5. Points to Note

Version-Wise Limitations
  1. The tasks that can be performed from within the widget are limited to the ones pertaining to a version. For example, say you want to execute the JS API v2 Get Records task from within a widget. The records will be fetched only if you've provided the CDN URL pertaining to v2 in the widget's HTML file.
  2. If you need to change the current JS API version, the following changes have to be done:
    1. Change the CDN URL in the widget ZIP's HTML file to the required version
    2. SDK initialization is required only for JS API v1. Add or remove the initialization method based on the required version, in the widget ZIP's JS file.
    3. Update the syntax and configuration parameters of the JS API tasks to match those of the required version, in the widget ZIP's JS file.
The widget file needs to be re-uploaded afterwards. Keep in mind that after the CDN URL is updated, any tasks from the version used before will stop working.
General
  1. Any changes to the JS script present in a widget's file will require re-uploading the modified file for the widget to work as required.
  2. Make sure to provide the mandatory parameters necessary for a task in the configuration for successful execution.
  3. Only Publish API tasks will work in published pages that can be accessed by people who do not hold a Creator account.

Helpful?21
Updated: 6 days ago
Share :