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
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 to create.
Returns
The created task.
Return Type:
NAME
TYPE
DESCRIPTION
Date and time the task was created.
Task ID.
Date and time the task was last updated.
Information about the contact associated with the task.
Description of the task.
Due date for the task.
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.
Details about the task source.
Status of the task.
Supported values: "ACTION_NEEDED"
, "COMPLETED"
.
Default: "ACTION_NEEDED"
Title of the task.
Was this helpful?
12import { tasks } from 'wix-crm.v2';34/* 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*/1516export async function myCreateTaskFunction(task) {1718 try {19 const newTask = await tasks.createTask(task);20 console.log('Successfully created a new task:', newTask);2122 return newTask;23 }24 catch(error){25 console.log(error);26 // Handle the error27 }28}2930/* 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
1import { Permissions, webMethod } from 'wix-web-module';2import { tasks } from 'wix-crm.v2';3import { elevate } from 'wix-auth';45/* 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*/1617export 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);2223 return newTask;24 }25 catch(error){26 console.log(error);27 // Handle the error28 }29});3031/* 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