Search.../

createTask( )

Creates a new task.

Description

All fields in the task object are optional. If you don't pass any fields in the task object, the function returns a task with the following core properties:

  • _id
  • _createdDate
  • _updatedDate
  • status
  • source
  • revision
Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function createTask(task: Task): Promise<Task>

createTask Parameters

NAME
TYPE
DESCRIPTION
task
Task

Task to create.

Returns

The created 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?

Create a new task (dashboard page code)

Copy Code
1
2import { tasks } from 'wix-crm.v2';
3
4/* Sample task value:
5 * {
6 * contact: {
7 * _id: '5518ee7f-270e-40c4-b756-dad56e8f0ffc'
8 * },
9 * description: 'Send a follow up email',
10 * dueDate: new Date(2024, 1, 31),
11 * status: 'ACTION_NEEDED',
12 * title: 'Follow up'
13 * }
14*/
15
16export async function myCreateTaskFunction(task) {
17
18 try {
19 const newTask = await tasks.createTask(task);
20 console.log('Successfully created a new task:', newTask);
21
22 return newTask;
23 }
24 catch(error){
25 console.log(error);
26 // Handle the error
27 }
28}
29
30/* Promise resolves to:
31 * {
32 * "revision": "1",
33 * "title": "Follow up",
34 * "description": "Send a follow up email",
35 * "dueDate": "2024-01-31T00:00:00.000Z",
36 * "status": "ACTION_NEEDED",
37 * "source": {
38 * "sourceType": "APP",
39 * "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a"
40 * },
41 * "contact": {
42 * "firstName": "Sally",
43 * "lastName": "Smith",
44 * "email": "sally.smith@example.com",
45 * "phone": "+1 524-624-2486",
46 * "_id": "5518ee7f-270e-40c4-b756-dad56e8f0ffc"
47 * },
48 * "_id": "37c2c378-8085-4ef7-8a3e-6f341248e757",
49 * "_createdDate": "2024-01-18T12:16:37.452Z",
50 * "_updatedDate": "2024-01-18T12:16:37.452Z"
51 * }
52*/
53
Create a new 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 task value:
6 * {
7 * contact: {
8 * _id: '5518ee7f-270e-40c4-b756-dad56e8f0ffc'
9 * },
10 * description: 'Send a follow up email',
11 * dueDate: new Date(2024, 1, 31),
12 * status: 'ACTION_NEEDED',
13 * title: 'Follow up'
14 * }
15*/
16
17export const myCreateTaskFunction = webMethod(Permissions.Anyone, async (task) => {
18 try {
19 const elevatedCreateTask = elevate(tasks.createTask);
20 const newTask = await elevatedCreateTask(task);
21 console.log('Successfully created a new task:', newTask);
22
23 return newTask;
24 }
25 catch(error){
26 console.log(error);
27 // Handle the error
28 }
29});
30
31/* Promise resolves to:
32 * {
33 * "revision": "1",
34 * "title": "Follow up",
35 * "description": "Send a follow up email",
36 * "dueDate": "2024-01-31T00:00:00.000Z",
37 * "status": "ACTION_NEEDED",
38 * "source": {
39 * "sourceType": "APP",
40 * "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a"
41 * },
42 * "contact": {
43 * "firstName": "Sally",
44 * "lastName": "Smith",
45 * "email": "sally.smith@example.com",
46 * "phone": "+1 524-624-2486",
47 * "_id": "5518ee7f-270e-40c4-b756-dad56e8f0ffc"
48 * },
49 * "_id": "37c2c378-8085-4ef7-8a3e-6f341248e757",
50 * "_createdDate": "2024-01-18T12:16:37.452Z",
51 * "_updatedDate": "2024-01-18T12:16:37.452Z"
52 * }
53*/
54