Retrieves a single document from the server based on the provided parameters.

This function performs an asynchronous request to the server to get a document of the specified doctype. It supports parameters for specifying the document's name, applying filters, and including a parent document.

// Retrieve a document of type 'Employee' with a specific name.
const params: getDocParams = {
doctype: 'Employee',
name: 'EMP-001',
};
const employee = await getDoc(params);
console.log(employee); // Logs the 'Employee' document with name 'EMP-001'
// Get a document of type 'Product' with a specific filter.
const params: getDocParams = {
doctype: 'Product',
filters: { status: 'Available' },
};
const product = await getDoc(params);
console.log(product); // Logs a 'Product' document that matches the filter
// Retrieve a document of type 'Order' with a parent document specified.
const params: getDocParams = {
doctype: 'Order',
parent: 'TASK-001',
};
const order = await getDoc(params);
console.log(order); // Logs the 'Order' document associated with parent 'TASK-001'
// Fetch a document of type 'Invoice' with both a specific name and filters applied.
const params: getDocParams = {
doctype: 'Invoice',
name: 'INV-123',
filters: { status: 'Paid' },
};
const invoice = await getDoc(params);
console.log(invoice); // Logs the 'Invoice' document with name 'INV-123' and status 'Paid'

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

  • Type Parameters

    Parameters

    • params: getDocParams

      The parameters to customize the query. This includes:

      • doctype: The document type to retrieve.
      • name: Optional name of the specific document to retrieve.
      • filters: Optional filter conditions to apply to the query.
      • parent: Optional parent document identifier.

    Returns Promise<T>

    A promise that resolves to the document of type T. The exact type of T depends on the structure of the document and any specified parameters.