Search.../

createTask( )

Creates a new task.

Description

The createTask() function returns a Promise that resolves to the ID of the the newly created task after it has been successfully created.

When creating a new task, the specified TaskInfo object must contain a title value.

Syntax

function createTask(taskInfo: TaskInfo): Promise<string>

createTask Parameters

NAME
TYPE
DESCRIPTION
taskInfo
TaskInfo

The information to use when creating the task.

Returns

Fulfilled - ID of the newly created task.

Return Type:

Promise<string>

Was this helpful?

Create a new task

Copy Code
1import {tasks} from 'wix-crm-backend';
2
3export function createTask(title, contactId, dueDate) {
4 const taskInfo = {
5 "title": title,
6 "contactId": contactId,
7 "dueDate": dueDate
8 };
9
10 return tasks.createTask(taskInfo);
11}
12
13// Returns promise that resolves to:
14// 3c9683ea-f6cc-470b-b0d1-2eb6b8cea912
Create a new task on button click

This example demonstrates how to create a task to follow up with the current user in a month's time when the user clicks a Follow Up button.

Copy Code
1/****************************
2 * Backend code - tasks.jsw *
3 ****************************/
4import { tasks } from 'wix-crm-backend';
5import wixUsers from 'wix-users-backend';
6
7export function createFollowUpTask() {
8 let followUpDate = new Date();
9 followUpDate.setMonth(followUpDate.getMonth() + 1);
10
11 const taskInfo = {
12 "title": "Follow Up",
13 "contactId": wixUsers.currentUser.id,
14 "dueDate": followUpDate
15 };
16
17 return tasks.createTask(taskInfo);
18}
19
20/*************
21 * page code *
22 *************/
23import { createFollowUpTask } from 'backend/tasks';
24
25// ..
26
27export function followUpButton_click(event) {
28 createFollowUpTask()
29 .then((result) => {
30 console.log(result); // "3c9683ea-f6cc-470b-b0d1-2eb6b8cea912"
31 })
32 .catch((error) => {
33 console.log(error);
34 });
35}
36