Renames an existing document in the database.

This function performs an asynchronous request to the server to rename a document of the specified type. It updates the document's name from the old_name to the new_name. Optionally, if merge is set to true, the function will merge the old document into the new document if it exists, preserving related data.

// Rename an 'Employee' document from 'EMP-001' to 'EMP-1001' without merging.
const renameParams: renameDocParams = {
doctype: 'Employee',
old_name: 'EMP-001',
new_name: 'EMP-1001',
};
const success = await renameDoc(renameParams);
console.log(success); // Logs `true` if the document was successfully renamed
// Rename a 'Product' document from 'PRD-123' to 'PRD-1234', merging if the new name already exists.
const renameParams: renameDocParams = {
doctype: 'Product',
old_name: 'PRD-123',
new_name: 'PRD-1234',
merge: true,
};
const success = await renameDoc(renameParams);
console.log(success); // Logs `true` if the document was successfully renamed and merged
// Rename an 'Order' document from 'ORD-456' to 'ORD-4567', without merging.
const renameParams: renameDocParams = {
doctype: 'Order',
old_name: 'ORD-456',
new_name: 'ORD-4567',
};
const success = await renameDoc(renameParams);
console.log(success); // Logs `true` if the document was successfully renamed

Throws an error if the request fails or if there is an issue with the renaming operation.

  • Parameters

    • params: renameDocParams

      The parameters for renaming the document. This includes:

      • doctype: The document type of the document to be renamed.
      • old_name: The current name of the document to be renamed.
      • new_name: The new name for the document.
      • merge (optional): A boolean indicating whether to merge the old document into the new one if the new name already exists. Defaults to false.

    Returns Promise<boolean>

    A promise that resolves to true if the document was successfully renamed, or false if the operation failed.