Sets the value of a specific field in a document of the given doctype.

This function performs an asynchronous request to the server to update the value of a specified field in a document of the provided doctype. This function is useful for modifying individual field values in existing documents.

// Update the 'company_name' field in the 'Company' document with name 'COMP-123' to 'New Company Name'.
const params: setValueParams = {
doctype: 'Company',
name: 'COMP-123',
fieldname: 'company_name',
value: 'New Company Name',
};
const updatedCompany = await setValue(params);
console.log(updatedCompany); // Logs the updated 'Company' document with the new company name
// Set the 'status' field in an 'Order' document with name 'ORD-456' to 'Shipped'.
const params: setValueParams = {
doctype: 'Order',
name: 'ORD-456',
fieldname: 'status',
value: 'Shipped',
};
const updatedOrder = await setValue(params);
console.log(updatedOrder); // Logs the updated 'Order' document with status 'Shipped'
// Change the 'price' field value in the 'Product' document with name 'PRD-789' to 199.99.
const params: setValueParams = {
doctype: 'Product',
name: 'PRD-789',
fieldname: 'price',
value: 199.99,
};
const updatedProduct = await setValue(params);
console.log(updatedProduct); // Logs the updated 'Product' document with the new price

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

  • Type Parameters

    Parameters

    • params: setValueParams

      The parameters for the update request. This includes:

      • doctype: The document type where the field value should be set.
      • name: The name of the document (or document identifier) where the field value should be updated.
      • fieldname: The name of the field whose value is to be set.
      • value: The new value to set for the specified field.

    Returns Promise<T>

    A promise that resolves to the updated document of type T. The type T depends on the structure of the document and the parameters provided.