Search.../

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.

Admin Method

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
_id
string

Task ID.

task
UpdateTask

Task to update.

Returns

The updated task.

Return Type:

Promise<
Task
>
NAME
TYPE
DESCRIPTION
_createdDate
Date

Date and time the task was created.

_id
string

Task ID.

_updatedDate
Date

Date and time the task was last updated.

contact
ContactInfo

Information about the contact associated with the task.

description
string

Description of the task.

dueDate
Date

Due date for the task.

revision
string

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.

source
TaskSource

Details about the task source.

status
string

Status of the task.

Supported values: "ACTION_NEEDED", "COMPLETED".

Default: "ACTION_NEEDED"

title
string

Title of the task.

Was this helpful?

Partially update a task (dashboard page code)

Copy Code
1
2import { tasks } from 'wix-crm.v2';
3
4/* Sample _id value:
5 * '3a49f901-62d5-4ca2-a8e8-395c562a3f7b'
6 *
7 * Sample task value:
8 * {
9 * revision: 2,
10 * status: 'COMPLETED',
11 * title: 'Send email
12 * }
13 */
14
15 export async function myUpdateTaskFunction(_id, task) {
16
17 try {
18 const updatedTask = await tasks.updateTask(_id, task);
19
20 return updatedTask;
21 } catch (error) {
22 console.log(error);
23 // Handle the error
24 }
25}
26
27/* 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
Partially update a task (export from backend code)

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { tasks } from 'wix-crm.v2';
3import { elevate } from 'wix-auth';
4
5/* Sample _id value:
6 * '3a49f901-62d5-4ca2-a8e8-395c562a3f7b'
7 *
8 * Sample task value:
9 * {
10 * revision: 2,
11 * status: 'COMPLETED',
12 * title: 'Send email
13 * }
14 */
15
16export const myUpdateTaskFunction = webMethod(Permissions.Anyone, async (_id, task) => {
17 try {
18 const elevatedUpdateTask = elevate(tasks.updateTask);
19 const updatedTask = await elevatedUpdateTask(_id, task);
20
21 return updatedTask;
22 } catch (error) {
23 console.log(error);
24 // Handle the error
25 }
26});
27
28/* 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
Update task

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { tasks } from 'wix-crm.v2';
3import { elevate } from 'wix-auth';
4
5/* 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 */
20
21export const myUpdateTaskFunction = webMethod(Permissions.Anyone, async (_id, task) => {
22
23 try {
24 const elevatedUpdateTask = elevate(tasks.updateTask);
25 const updatedTask = await elevatedUpdateTask(_id, task);
26
27 return updatedTask;
28 } catch (error) {
29 console.log(error);
30 // Handle the error
31 }
32});
33
34
35
36
37/* 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 */