Fetches a list of documents from the server based on the provided parameters.

This function performs an asynchronous request to the server to retrieve a list of documents of the specified doctype. It supports various parameters to customize the query, such as selecting specific fields, applying filters, sorting, grouping, and pagination.

// Retrieve all documents of type 'Employee' with default fields.
const params: GetListParams = {
doctype: 'Employee',
};
const employees = await getList(params);
console.log(employees); // Logs all employees
// Fetch documents of type 'Product' including only 'name' and 'price' fields.
const params: GetListParams = {
doctype: 'Product',
fields: ['name', 'price'],
};
const products = await getList(params);
console.log(products); // Logs products with 'name' and 'price' fields
// Get documents of type 'Task' where status is 'Open'.
const params: GetListParams = {
doctype: 'Task',
filters: { status: 'Open' },
};
const openTasks = await getList(params);
console.log(openTasks); // Logs tasks with status 'Open'
// Retrieve 'Order' documents, grouped by 'customer' and sorted by 'date' in descending order.
const params: GetListParams = {
doctype: 'Order',
order_by: 'date desc',
group_by: 'customer',
};
const orders = await getList(params);
console.log(orders); // Logs orders grouped by customer and sorted by date
// Fetch 5 'Invoice' documents starting from the 11th record.
const params: GetListParams = {
doctype: 'Invoice',
limit_start: 10,
limit_page_length: 5,
};
const invoices = await getList(params);
console.log(invoices); // Logs 5 invoices starting from the 11th record
// Retrieve 'Employee' documents from either 'Sales' or 'Marketing' departments.
const params: GetListParams = {
doctype: 'Employee',
or_filters: [["department", "=", "Marketing"], ["department", "=", "Sales"]]
};
const employees = await getList(params);
console.log(employees); // Logs employees from Sales or Marketing departments
// Get 'Event' documents with debug information, not as dictionary format.
const params: GetListParams = {
doctype: 'Event',
debug: true,
as_dict: false,
};
const events = await getList(params);
console.log(events); // Logs events with debug info and in a non-dictionary format
// Fetch 'Comment' documents related to parent document 'TASK-001'.
const params: GetListParams = {
doctype: 'Comment',
parent: 'TASK-001',
};
const comments = await getList(params);
console.log(comments); // Logs comments related to the parent document 'TASK-001'

Throws an error if the request fails or if there is an issue processing the parameters.

  • Type Parameters

    Parameters

    • params: GetListParams

      The parameters to customize the query. This includes:

      • doctype: The document type to retrieve.
      • fields: Optional list of fields to include in the result.
      • filters: Optional filters to apply to the query.
      • group_by: Optional field by which to group results.
      • order_by: Optional sorting criteria.
      • limit_start: Optional starting index for pagination.
      • limit_page_length: Optional number of results per page.
      • parent: Optional parent document identifier.
      • debug: Optional flag to enable debugging.
      • as_dict: Optional flag to specify the format of the results.
      • or_filters: Optional additional filter conditions with OR logic.

    Returns Promise<T[]>

    A promise that resolves to an array of documents of type T. The exact type of T depends on the structure of the documents and the as_dict parameter.