> ## 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.

# Get appointments

> How to get appointments with CRMScript

<Tip>
  You can only retrieve appointments for persons that are SuperOffice users ([associates][1]).

  The signed-in user must also have permission to view those appointments. Otherwise, an exception is thrown.
</Tip>

## NSAppointment\[] GetAppointmentList(Integer\[] ids)

Fetches a collection of appointments corresponding to a list of IDs.

```crmscript! theme={null}
Integer[] appointmentIDs;
appointmentIDs.pushFront(84);
appointmentIDs.pushFront(86);
appointmentIDs.pushFront(88);
NSAppointmentAgent appointmentAgent;
NSAppointment[] appointmentList = appointmentAgent.GetAppointmentList(appointmentIDs);

for(Integer i = 0; i < appointmentList.length(); i++) {
  print("ID: " + appointmentList[i].GetAppointmentId().toString());
  printLine("\t At: " + appointmentList[i].GetStartDate().toString() + " to " + appointmentList[i].GetEndDate().toString());
}
```

<Tip>
  You can also use the [archive agent][2] to fetch appointments.
</Tip>

## NSAppointment\[] GetPersonDiary(Integer personId, DateTime startTime, DateTime endTime, Integer count)

Fetches a limited number of appointments within a time range for the given person. `GetPersonDiary()` will ignore appointments not shown in the user's diary.

```crmscript! theme={null}
NSAppointmentAgent appointmentAgent;
DateTime start;
DateTime end;

NSAppointment[] appointmentList = appointmentAgent.GetPersonDiary(5, start.addMonth(-6), end, 10);

for(Integer i = 0; i < appointmentList.length(); i++) {
  print("ID: " + appointmentList[i].GetAppointmentId().toString());
  printLine("\t At: " + appointmentList[i].GetStartDate().toString() + " to " + appointmentList[i].GetEndDate().toString());
}
```

<Tip>
  Set `count` to -1 to not restrict the collection of appointments retrieved.
</Tip>

## NSAppointment\[] GetPersonAppointments(Integer personId, Bool includeProjectAppointments, DateTime startTime, DateTime endTime, Integer count)

Same as `GetPersonDiary()`, but will also include all appointments in projects that the user is a member of if set to **true**.

```crmscript! theme={null}
NSAppointmentAgent appointmentAgent;
DateTime start;
DateTime end;

NSAppointment[] appointmentList = appointmentAgent.GetPersonAppointments(5, true, start.addMonth(-6), end, 5);

for(Integer i = 0; i < appointmentList.length(); i++) {
  printLine("ID: " + appointmentList[i].GetAppointmentId().toString());
}
```

[1]: ../../../../contact/dev/index#associate

[2]: ../../netserver/crmscript-archiveagent


## Related topics

- [Get Appointment](/en/api/reference/restful/agent/appointment_agent/get-appointment.md)
- [Appointment](/en/api/archive-providers/reference/appointment.md)
- [Get Appointment From U I D](/en/api/reference/restful/agent/appointment_agent/get-appointment-from-u-i-d.md)
- [Get Appointment Entity](/en/api/reference/restful/rest/appointment/get-appointment-entity.md)
- [Get Appointment List](/en/api/reference/restful/agent/appointment_agent/get-appointment-list.md)
