updateTask( )
Updates a task.
Description
Each time the task is updated, revision
increments by 1.
The existing revision
must be included when updating the task.
This ensures you're working with the latest task
and prevents unintended overwrites.
This function requires elevated permissions to run. This function is not universal and runs only on the backend.
Syntax
function updateTask(_id: string, task: UpdateTask): Promise<Task>
updateTask Parameters
NAME
TYPE
DESCRIPTION
Task ID.
Task to update.
Returns
The updated task.
Return Type:
NAME
TYPE
DESCRIPTION
Date and time the task was created.
Task ID.
Date and time the task was last updated.
Information about the contact associated with the task.
Description of the task.
Due date for the task.
Revision number, which increments by 1 each time the task is updated. To prevent conflicting changes, the existing revision
must be used when updating a task.
Details about the task source.
Status of the task.
Supported values: "ACTION_NEEDED"
, "COMPLETED"
.
Default: "ACTION_NEEDED"
Title of the task.
Was this helpful?
12import { tasks } from 'wix-crm.v2';34/* Sample _id value:5 * '3a49f901-62d5-4ca2-a8e8-395c562a3f7b'6 *7 * Sample task value:8 * {9 * revision: 2,10 * status: 'COMPLETED',11 * title: 'Send email12 * }13 */1415 export async function myUpdateTaskFunction(_id, task) {1617 try {18 const updatedTask = await tasks.updateTask(_id, task);1920 return updatedTask;21 } catch (error) {22 console.log(error);23 // Handle the error24 }25}2627/* Promise resolves to:28 * {29 * "revision": "3",30 * "title": "Send email",31 * "dueDate": "2024-02-08T10:00:00.000Z",32 * "status": "COMPLETED",33 * "source": {34 * "sourceType": "USER",35 * "userId": "162e6672-d392-42f8-bf79-999ee633c92a"36 * },37 * "contact": {38 * "firstName": "Jane",39 * "lastName": "Doe",40 * "email": "jane.doe1@example.com",41 * "phone": "+1 214-533-2543",42 * "_id": "dfcb4c01-7336-4b59-ae43-957cb89952ce"43 * },44 * "_id": "3a49f901-62d5-4ca2-a8e8-395c562a3f7b",45 * "_createdDate": "2024-01-18T13:40:56.414Z",46 * "_updatedDate": "2024-01-18T15:44:52.606Z"47 * }48 */49
1import { Permissions, webMethod } from 'wix-web-module';2import { tasks } from 'wix-crm.v2';3import { elevate } from 'wix-auth';45/* Sample _id value:6 * '3a49f901-62d5-4ca2-a8e8-395c562a3f7b'7 *8 * Sample task value:9 * {10 * revision: 2,11 * status: 'COMPLETED',12 * title: 'Send email13 * }14 */1516export const myUpdateTaskFunction = webMethod(Permissions.Anyone, async (_id, task) => {17 try {18 const elevatedUpdateTask = elevate(tasks.updateTask);19 const updatedTask = await elevatedUpdateTask(_id, task);2021 return updatedTask;22 } catch (error) {23 console.log(error);24 // Handle the error25 }26});2728/* Promise resolves to:29 * {30 * "revision": "3",31 * "title": "Send email",32 * "dueDate": "2024-02-08T10:00:00.000Z",33 * "status": "COMPLETED",34 * "source": {35 * "sourceType": "USER",36 * "userId": "162e6672-d392-42f8-bf79-999ee633c92a"37 * },38 * "contact": {39 * "firstName": "Jane",40 * "lastName": "Doe",41 * "email": "jane.doe1@example.com",42 * "phone": "+1 214-533-2543",43 * "_id": "dfcb4c01-7336-4b59-ae43-957cb89952ce"44 * },45 * "_id": "3a49f901-62d5-4ca2-a8e8-395c562a3f7b",46 * "_createdDate": "2024-01-18T13:40:56.414Z",47 * "_updatedDate": "2024-01-18T15:44:52.606Z"48 * }49 */50
1import { Permissions, webMethod } from 'wix-web-module';2import { tasks } from 'wix-crm.v2';3import { elevate } from 'wix-auth';45/* Sample _id value:6 * '3a49f901-62d5-4ca2-a8e8-395c562a3f7b'7 *8 * Sample task value:9 * {10 * revision: 3,11 * contact: {12 * _id: 'dfcb4c01-7336-4b59-ae43-957cb89952ce'13 * },14 * description: 'Send follow up email email',15 * dueDate: new Date(2024, 3, 16),16 * status: 'ACTION_NEEDED',17 * title: 'Follow up'18 * }19 */2021export const myUpdateTaskFunction = webMethod(Permissions.Anyone, async (_id, task) => {2223 try {24 const elevatedUpdateTask = elevate(tasks.updateTask);25 const updatedTask = await elevatedUpdateTask(_id, task);2627 return updatedTask;28 } catch (error) {29 console.log(error);30 // Handle the error31 }32});3334353637/* Promise resolves to:38 * {39 * "revision": "4",40 * "title": "Follow up",41 * "description": "Send follow up email email",42 * "dueDate": "2024-04-16T00:00:00.000Z",43 * "status": "ACTION_NEEDED",44 * "source": {45 * "sourceType": "USER",46 * "userId": "162e6672-d392-42f8-bf79-999ee633c92a"47 * },48 * "contact": {49 * "firstName": "Jane",50 * "lastName": "Doe",51 * "email": "jane.doe1@example.com",52 * "phone": "+1 214-533-2543",53 * "_id": "dfcb4c01-7336-4b59-ae43-957cb89952ce"54 * },55 * "_id": "3a49f901-62d5-4ca2-a8e8-395c562a3f7b",56 * "_createdDate": "2024-01-18T13:40:56.414Z",57 * "_updatedDate": "2024-01-18T15:49:53.065Z"58 * }59 */