Create Record
Table of Contents
Overview
This task is used to add a new record with the specified values into a Zoho Cliq database.
This task is based on Zoho Cliq API - Add a record.
Syntax
<variable> = zoho.cliq.createRecord(<database_name>, <data_map>, <connection>);
Params | Data type | Description |
<variable> | KEY-VALUE | specifies the variable which will hold the response returned by Zoho Cliq. |
<database_name> | TEXT | specifies the unique name of the database into which the new record will be added. |
<data_map> | KEY-VALUE | specifies the content of the new record, each key representing a unique column name from the database and value representing its corresponding data to be added |
<connection> | TEXT | specifies the link name of the Zoho Cliq connection Note:
|
Example 1: Creating a record with static values
The following script adds a new record with the specified values into the Zoho Cliq database - availabilitydatabase.
values_map=Map(); values_map.put("name","John"); values_map.put("empid","1"); values_map.put("availability","true"); response_map = zoho.cliq.createRecord("availabilitydatabase", values_map, "cliq_connection");
where,
response_map
"availabilitydatabase"
values_map
"cliq_connection"
Example 2: Creating a record with dynamic values
Write the below script in the message handler of your Bot configuration to make it add a new record into the Zoho Cliq database - availabilitydatabase. The values of the fields name and empid are Shawn and 2 respectively. The value of the availability field is adjusted based on the user's response. If the user sends YES to the Bot, the availability field is filled up with true. Otherwise, it is filled up with the default value false.
response=Map(); values_map=Map(); values_map.put("name","Shawn"); values_map.put("empid","2"); dynamic_value=false; if(message.equalsIgnoreCase("YES")){ dynamic_value=true; } values_map.put("availability",dynamic_value); text = zoho.cliq.createRecord("availabilitydatabase", values_map, "cliq_connection"); response.put("text",text); return response;
where,
values_map
message
dynamic_value
"availabilitydatabase"
text
"cliq_connection"
The following is the response of the above script when the user sends YES.
Sample Response
Success Response
The success response returned is of the following format
{
"status":"SUCCESS",
"url":"/api/v2/storages/availabilitydatabase/records",
"object":{"empid":"1","name":"John","availability":true,"id":"1775XXXX0002XXXX009"}
}
To fetch the ID of the newly created record, execute the following snippet:
Failure Response
The failure response returned for an incorrect database name is of the following format
{
"status":"FAILURE",
"message":"Uh-oh! Looks like availablitydata does not exist.",
"code":"platform_storage_database_not_found"
}The failure response returned for an incorrect or non-existent field name is of the following format
{
"status":"FAILURE", "message":"The designation column does not exist.", "code":"platform_storage_column_not_exists"
}The failure response for a missing mandatory field is of the following format
{
"status":"FAILURE",
"message":"You have to specify a value for the mandatory column empid",
"code":"platform_storage_required_field_value_missing"
}The failure response for a data type mismatch is of the following format
{
"status":"FAILURE",
"message":"Invalid value given for field availability value yes.",
"code":"platform_storage_fields_invalid_value"
}The failure response for a duplicate value in unique column is of the following format
{
"status":"FAILURE",
"message":"Looks like this record is a duplicate entry and hence cannot be added!",
"code":"platform_storage_unique_key_constraint_violated"
}
Related Tasks
- Zoho Cliq API
- Common error codes can be viewed here