Zum Hauptinhalt springen

getAttachmentByFileName

This function retrieves a file attachment as a Blob object by searching for its filename. By default, it searches attachments associated with the current record, but you can also specify a different app or record ID to search.

Syntax

app.getAttachmentByFileName(fileName, attachmentApp, recordId)

Parameters

ParameterTypeDescription
fileNameStringThe name of the file to retrieve
attachmentAppString(Optional) The name of a different app to search for attachments. If not specified, uses the current app
recordIdString/Number(Optional) The ID of a record to search for attachments. If not specified, uses the current record's ID

Return Value

Returns a Promise that resolves to:

  • A Blob object containing the file data if found
  • null if the file is not found

Examples

Example 1: Get an attachment from the current record:

// Get an invoice PDF from the current record
const pdfBlob = app.getAttachmentByFileName("Invoice1234.pdf");

// Display the PDF in a document viewer control
app.showBlob("docViewer", pdfBlob);

Example 2: Get an attachment from a specific record in the current app:

// Get a document from a specific customer record
const contractBlob = app.getAttachmentByFileName("Contract.pdf", null, 1234);

// Prompt user to save the file
saveBlob(contractBlob, "Customer1234_Contract.pdf");

Example 3: Get an attachment from a record in a different app:

// Get an attachment from the "documents" app, record #5678
const letterBlob = app.getAttachmentByFileName(
"ConfirmationLetter.pdf",
"documents",
5678
);

Notes

  • The function is asynchronous and returns a Promise
  • The search is case-sensitive; "invoice.pdf" and "Invoice.PDF" are treated as different files
  • If multiple files with the same name exist, the first matching file is returned
  • For more flexibility in attachment handling, consider using:
    • getAttachmentByName() - To get metadata instead of the file blob
    • getAttachmentById() - To retrieve a file by its unique ID
    • getAttachmentsForCurrentRecord() - To get a list of all attachments for filtering