> ## Documentation Index
> Fetch the complete documentation index at: https://docs.superoffice.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Todo list

> How to create and complete to-dos with CRMScript

## Create a to-do

The following code sample will create a to-do (task ID = 6) due at the end of the current day. It applies to associate with ID 1.

```crmscript theme={null}
Integer owner = 1; // associate.associate_id

NSContact myCompany;
myCompany.SetContactId(2); // contact.contact_id

DateTime deadline;
deadline.moveToDayEnd();

NSAppointmentAgent appointmentAgent;
NSAppointmentEntity newTask = appointmentAgent.CreateDefaultAppointmentEntityByTypeAndAssociate(6, owner);

newTask.SetDescription("Remember to turn off the lights when you leave the office.");
newTask.SetContact(myCompany);
newTask.SetAssignmentStatus(11);
newTask.SetEndDate(deadline);

newTask = appointmentAgent.SaveAppointmentEntity(newTask);
```

<Note>
  While the to-do technically doesn't have a start time, that field will be set with a default value. For example, noon the current day. Don't assume that the start time is empty.
</Note>

## Complete a to-do

To mark a to-do as completed is essentially just to set the **status** to 3.

This example completes the to-do with ID 88, with end-time = now and start-time = 5 minutes ago.

```crmscript theme={null}
DateTime start;
DateTime end;
NSAppointmentAgent appointmentAgent;
appointmentAgent.UpdateAppointment(88, start.addMin(-5), end, 3, 2, 5);
```

## List overdue to-dos

```crmscript theme={null}
DateTime now;
SearchEngine se;
se.addFields("appointment", "appointment_id,task_idx,status,endDate");
se.addCriteria("appointment.task_idx.record_type", "OperatorEquals", "6","OperatorAnd", 0);
se.addCriteria("appointment.status", "OperatorEquals", "1","OperatorAnd", 0);
se.addCriteria("appointment.endDate", "OperatorLt", now.toString(), "OperatorAnd", 0);
printLine(se.executeTextTable());
```

This sample will list all follow-ups of type 6 that have not been started and a deadline in the past.

## Related topics

* [NSAppointmentAgent][1]
* [NSAppointmentEntity][2]
* [Working with CRMScript SearchEngine][3]
* [Create appointment][4]
* [About todo lists][5]

[1]: /en/automation/crmscript/reference/CRMScript.NetServer.NSAppointmentAgent

[2]: /en/automation/crmscript/reference/CRMScript.NetServer.NSAppointmentEntity

[3]: ../../searchengine/index

[4]: ./create-appointment

[5]: ../../../../diary/learn/follow-ups#todo


## Related topics

- [Diary](/en/diary/learn/index.md)
- [Follow-ups](/en/diary/learn/follow-ups.md)
- [Working with follow-ups (appointments) in API](/en/diary/dev/index.md)
- [Activities tab](/en/learn/section-tabs/activities-tab.md)
- [NSTaskListItem](/en/automation/crmscript/reference/CRMScript.NetServer.NSTaskListItem.md)
- [Add follow-up](/en/diary/learn/create-follow-up.md)
