Update Records in Zoho Sheet
Table of Contents
Description
The zoho.sheet.updateRecords task is used to update rows that satisfy the specified criteria with new values in Zoho Sheet. This task is based on the Zoho Sheet API - Update records in worksheet.
Syntax
<response> = zoho.sheet.updateRecords(<resource_id>, <worksheet_name>, <criteria>, <data_map>, <optional_map>, <connection>);
Params | Data type | Description |
<response> | KEY-VALUE | The details of the updated records and status of the executed task. |
<resource_id> | TEXT | The ID of the Zoho Sheet file in which the records need to be updated. Note: The resource_id can be obtained from the URL of the Zoho sheet file. The URL is in the following format: https://sheet.zoho.com/sheet/open/<resource_id>/sheets/<worksheet_name> |
<worksheet_name> | TEXT | The name of the worksheet in which the rows need to be updated. |
<criteria> | TEXT | The search criteria that need to be satisfied by the records for them to be updated. To update all available rows without criteria, supply an empty text to this param. |
<data_map> | KEY-VALUE | The new values of the rows that need to be updated. Keys to this param must be supplied with column names. |
<optional_map> | KEY-VALUE | Any additional parameters supported by the Zoho Sheet API can be utilized using <optional_map>. The keys to this param need to be supplied with column names. To ignore querying using this param, supply an empty map. |
<connection> | TEXT | The link name of the connection. Note:
|
URL format: https://sheet.zoho.com/sheet/open/<resource_id>/sheets/<worksheet_name>
/ranges/<cell_range>
Example 1: Update records that satisfy the specified criteria
The following script updates the records of the worksheet - Sheet1 of the Zoho Sheet file with ID - eev4nXXXXXXXXXXXXXXXXXXXXXXXXXXXcff41:
new_values = Map(); new_values.put("Priority", "High"); queryData = Map(); response = zoho.sheet.updateRecords("eev4nXXXXXXXXXXXXXXXXXXXXXXXXXXXcff41", "Sheet1", "\"User Count\">=200", new_values, queryData, "sheet_connection");
where:
response
"eev4nXXXXXXXXXXXXXXXXXXXXXXXXXXXcff41"
"Sheet1"
"\"User Count\">=200"
new_values
"\"Priority\""
"\"High\""
queryData
"sheet_connection"
Example 2: Update only the first record that satisfies the specified criteria
The following script updates the first row that satisfies the criteria - "\"User Count\">=200" in the worksheet - Sheet1 of the Zoho Sheet file with ID - eev4nXXXXXXXXXXXXXXXXXXXXXXXXXXXcff41:
new_values = Map(); new_values.put("\"Priority\"","\"High\""); query_value = Map(); query_value.put("first_match_only","true"); response = zoho.sheet.updateRecords("eev4nXXXXXXXXXXXXXXXXXXXXXXXXXXXcff41", "Sheet1", "\"User Count\">=200", new_values, query_value, "sheet_connection");
where:
query_value
"first_match_only"
- If the values of the <data_map> and <optional_map> contain text entries (from the sheet), they need to be enclosed in double-quotes escaped by backslashes.
Example: Name = John Watson is provided as \"Name\" = \"John Watson\". - The following operators can be used to update rows that satisfy multiple criteria:
- and - Used between two criteria to fetch the rows that satisfy both conditions.
Example: The value - "\"Lead Source\"=\"Trade Show\" and \"User Count\">200" against the key - criteria in <query_map>, updates all the rows that have the value - Trade Show in the column - Lead Source and have a value greater than 200 in the column - User Count. - or - Used between two criteria to fetch the rows that satisfy either or both conditions.
Example: The value - "\"Lead Source\"=\"Trade Show\" or \"User Count\">200" against the key - criteria in <query_map>, updates all the rows that either has the value - Trade Show in the column - Lead Source or has a value greater than 200 in the column - User Count or both.
- and - Used between two criteria to fetch the rows that satisfy both conditions.
Response Format
Success Response
The success response will be returned in the following format:
{
"no_of_affected_rows":10,
"method":"worksheet.records.update",
"status":"success"
}
Failure Response
The failure response for invalid resource ID will be returned in the following format:
{
"error_message": "The workbook does not exists",
"error_code": 2862
}The failure response for an incorrect or non-existent worksheet name will be returned in the following format:
{
"error_message": "The sheet does not exists",
"method": "worksheet.jsondata.append",
"error_code": 2863,
"status": "failure"
}The failure response for invalid criteria will be returned in the following format:
{
"error_message": "Mentioned criteria is not valid",
"method": "worksheet.records.fetch",
"error_code": 2895,
"status": "failure"
}