🆕removeFile

To securely remove a file from a field or record

This function removes a file by specifying either:

  1. A file object which contains the necessary information (nid and the file name).

  2. nid and the file name as separate parameters.

The file object can either come from an Image field or be created using the file(this, "Name") function.

Syntax

removeFile(file, string)

removeFile(nid, string, string)

Return

void

When using the removeFile function on an Image field (removeFile(file)) the Image field itself is not automatically updated. This behavior is intentional.

To fully clear the file reference from an Image field, you need to manually set that Image field to null using scripting, such as:

removeFile(Image);
Image := null;

This ensures that both the file is removed and the field is properly cleared.

Examples

  1. Use removeFile(file) to remove an image attached to a record and displayed in an Image field:

removeFile(Image);
Image := null

Result: The image is removed from the record, and the Image field is set to empty.

  1. Use removeFile(nid, fileName) to remove a PDF attached to a record:

removeFile(this, "Offer_0724.pdf")

Result: The PDF "Offer_0724.pdf" is removed from the record.

You can use loops to remove multiple files in the same operation, though the process may be slow.

See also

renameFile which renames a file in a field or record.

importFile which imports a file from a URL and saves it as an attachment of a record.

shareFile which returns a URL of a specific file.

Last updated