removeFile

To securely remove a file from a field or record

This function removes a file by specifying either:

  • A file object that contains the necessary information (nid and the file name).

  • 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.

Caution: When using this function on native apps (iOS, iPadOS, macOS, Android), it must be enclosed in a do as server code block within the formula editor.

Syntax

removeFile(file, string)

removeFile(nid, string, string)

Return

void

Note: 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 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.

Note: 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