Retrieves a single value from a specific field in a document of the given doctype.

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 is designed for cases where only a single field's value is needed, without the need for additional filtering or complex queries.

// Retrieve the value of the 'company_name' field from a document of type 'Company'.
const params: getSingleValueParams = {
doctype: 'Company',
field: 'company_name',
};
const companyName = await getSingleValue(params);
console.log(companyName); // Logs the value of the 'company_name' field
// Get the value of the 'tax_rate' field from a 'Settings' document.
const params: getSingleValueParams = {
doctype: 'Settings',
field: 'tax_rate',
};
const taxRate = await getSingleValue(params);
console.log(taxRate); // Logs the value of the 'tax_rate' field
// Fetch the 'currency_symbol' field value from the 'Currency' doctype.
const params: getSingleValueParams = {
doctype: 'Currency',
field: 'currency_symbol',
};
const currencySymbol = await getSingleValue(params);
console.log(currencySymbol); // Logs the value of the 'currency_symbol' field

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

  • Parameters

    • params: getSingleValueParams

      The parameters for the query. This includes:

      • doctype: The document type from which to retrieve the value.
      • field: The name of the field whose value is to be retrieved.

    Returns Promise<string | number>

    A promise that resolves to the value of the specified field, which can be a string or a number.