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

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