Retrieves the value of a specific field from a document based on the provided parameters.

This function performs an asynchronous request to the server to get the value of a specific field from a document of the specified doctype. It supports parameters for filtering the documents, specifying a parent document, and enabling debugging. The function returns the value of the specified field as a string or number.

// Retrieve the value of the 'name' field from a document of type 'Employee' with specific filters.
const params: getValueParams = {
doctype: 'Employee',
fieldname: 'name',
filters: { employee_id: 'EMP-001' },
};
const name = await getValue(params);
console.log(name); // Logs the 'name' field value for the employee with ID 'EMP-001'
// Get the value of the 'price' field from a 'Product' document with debugging enabled.
const params: getValueParams = {
doctype: 'Product',
fieldname: 'price',
filters: { product_code: 'PRD-123' },
debug: true,
};
const price = await getValue(params);
console.log(price); // Logs the 'price' field value for the product with code 'PRD-123' with debug info
// Fetch the 'status' field value of an 'Order' document, including a parent document identifier.
const params: getValueParams = {
doctype: 'Order',
fieldname: 'status',
filters: { order_id: 'ORD-456' },
parent: 'TASK-789',
};
const status = await getValue(params);
console.log(status); // Logs the 'status' field value for the order with ID 'ORD-456', related to parent 'TASK-789'
// Retrieve the value of the 'total_amount' field from an 'Invoice' document without additional parameters.
const params: getValueParams = {
doctype: 'Invoice',
fieldname: 'total_amount',
};
const totalAmount = await getValue(params);
console.log(totalAmount); // Logs the 'total_amount' field value from the invoice

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

  • Parameters

    • params: getValueParams

      The parameters to customize the query. This includes:

      • doctype: The document type from which to retrieve the value.
      • fieldname: The name of the field whose value is to be retrieved.
      • filters: Optional filter conditions to apply to the query.
      • as_dict: Optional flag to specify the format of the results (true or false).
      • debug: Optional flag to enable debugging.
      • parent: Optional parent document identifier.

    Returns Promise<string | number>

    A promise that resolves to the value of the specified field as a string or number.