createTask( )
Deprecated. This function will continue to work, but a newer version is available at wix-crm.v2.Tasks.createTask().
Description
Migration Instructions
If this function is already in your code, it will continue to work. To stay compatible with future changes, migrate to
wix-crm.v2.Tasks.createTask()
.To migrate to the new function:
Add the new import statement:
javascript | Copy Codeimport { tasks } from 'wix-crm.v2'If you plan to migrate all functions that use
wixCrmBackend
, remove the originalimport wixCrmBackend
statement.Look for any code that uses
wixCrmBackend.tasks.createTask()
, and replace it with withtasks.createTask()
. Update your code to work with the newcreateTask()
call and response properties.Test your changes to make sure your code behaves as expected.
Creates a new task.
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
The information to use when creating the task.
Returns
Fulfilled - ID of the newly created task.
Return Type:
Was this helpful?
1import { Permissions, webMethod } from 'wix-web-module';2import { tasks } from 'wix-crm-backend';34export const createTask = webMethod(Permissions.Anyone, (title, contactId, dueDate) => {5 const taskInfo = {6 "title": title,7 "contactId": contactId,8 "dueDate": dueDate9 };1011 return tasks.createTask(taskInfo);12});1314// Returns promise that resolves to:15// 3c9683ea-f6cc-470b-b0d1-2eb6b8cea912
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.
1/****************************2 * Backend code - tasks.web.js *3 ****************************/4import { Permissions, webMethod } from 'wix-web-module';5import { tasks } from 'wix-crm-backend';6import wixUsers from 'wix-users-backend';78export const createFollowUpTask = webMethod(Permissions.Anyone, () => {9 let followUpDate = new Date();10 followUpDate.setMonth(followUpDate.getMonth() + 1);1112 const taskInfo = {13 "title": "Follow Up",14 "contactId": wixUsers.currentUser.id,15 "dueDate": followUpDate16 };1718 return tasks.createTask(taskInfo);19});2021/*************22 * page code *23 *************/24import { createFollowUpTask } from 'backend/tasks.web';2526// ..2728export function followUpButton_click(event) {29 createFollowUpTask()30 .then((result) => {31 console.log(result); // "3c9683ea-f6cc-470b-b0d1-2eb6b8cea912"32 })33 .catch((error) => {34 console.log(error);35 });36}