getAttachmentId
This function searches for an attachment with a specific filename and returns its unique ID. Unlike getAttachmentByFileName()
, which returns the actual file data, this function only returns the ID reference, making it more efficient when you only need the identifier.
Syntax
app.getAttachmentId(fileName, attachmentApp, recordId)
Parameters
Parameter | Type | Description |
---|---|---|
fileName | String | The name of the file to search for |
attachmentApp | String | (Optional) The name of a different app to search for attachments. If not provided, uses the current app |
recordId | Number | (Optional) The ID of a record to search for attachments. If not provided, uses the current record's ID |
Return Value
Returns a Promise that resolves to:
- The numeric ID of the attachment if found
null
if no attachment with the given name is found
Examples
Example 1: Get the ID of an attachment from the current record:
// Find the ID of an invoice PDF in the current record
const invoiceId = app.getAttachmentId("Invoice1234.pdf");
// Use the ID to download the attachment
if (invoiceId) {
app.downloadAttachment(invoiceId);
}
Example 2: Get the ID of an attachment from a different record in the current app:
// Find the ID of a contract in a specific customer record
const contractId = app.getAttachmentId("Contract.pdf", null, 1234);
// Use the ID for further processing
if (contractId) {
// Add a note about this contract to the system log
app.logAdd({
context: "contracts",
text: `Found contract with ID ${contractId}`,
status: "info"
});
}
Example 3: Get the ID of an attachment from a different app:
// Find the ID of an attachment in the "documents" app, record #5678
const documentId = app.getAttachmentId(
"ConfirmationLetter.pdf",
"documents",
5678
);
// Use the ID to retrieve the attachment info
if (documentId) {
const attachmentInfo = app.getAttachmentInfoById(documentId);
// Process attachment metadata
}
Notes
- 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's ID is returned
- This function is typically used when you need to reference an attachment (for linking, downloading, etc.) without working with its content directly
- For retrieving the actual file data, use
getAttachmentById()
orgetAttachmentByFileName()