getConfigRecordAttachmentIdByFileName
This function finds an attachment in a configuration record by its filename and returns its unique ID. It's specifically designed to work with config records rather than standard app records, allowing you to access attachments across different configuration tables.
Syntax
app.getConfigRecordAttachmentIdByFileName(configName, recordId, fileName)
Parameters
Parameter | Type | Description |
---|---|---|
configName | String | The name of the configuration that contains the record |
recordId | Number | The ID of the record that contains the attachment |
fileName | String | The name of the file to search for |
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 in the specified record
Examples
Example 1: Get an attachment ID from a configuration record:
// Find the ID of an invoice PDF in a customer order record
const attachmentId = app.getConfigRecordAttachmentIdByFileName(
"customerOrder",
1234,
"invoice.pdf"
);
// Use the ID to download the attachment
if (attachmentId) {
app.downloadAttachment(attachmentId);
}
Example 2: Check if a specific attachment exists in a configuration record:
// Check if a contract exists in a vendor record
const contractId = app.getConfigRecordAttachmentIdByFileName(
"vendors",
vendorId,
"contract.pdf"
);
if (contractId) {
// Contract exists, show it in a document viewer
const contractBlob = app.getAttachmentById(contractId);
app.showBlob("docViewer", contractBlob);
} else {
// Contract doesn't exist, show message
app.showErrorMessage("Missing Document", "No contract found for this vendor.");
}
Example 3: Find and copy an attachment from a configuration record to the current record:
// Find a template document in the templates configuration
const templateId = app.getConfigRecordAttachmentIdByFileName(
"documentTemplates",
5,
"quote_template.docx"
);
// Copy the template to the current record if found
if (templateId) {
// Get the template attachment
const templateBlob = app.getAttachmentById(templateId);
// Save as new attachment in current record
app.uploadBlobAsAttachment(templateBlob, "new_quote.docx");
}
Related Functions
loadConfigRecordById()
- For loading a complete config record by its IDgetAttachmentId()
- Similar function for regular app recordsgetAttachmentById()
- For retrieving the actual attachment content using its IDdownloadAttachment()
- For downloading an attachment using its IDgetConfigRecordById()
- For retrieving a specific configuration record
Notes
- This function is designed specifically for attachments in configuration tables, not regular app records
- The search is case-sensitive, so ensure the filename matches exactly
- If multiple files with the same name exist in the record, the first match is returned
- For accessing attachments in regular app records, use
getAttachmentId()
instead - Use this function when you need to reference a document in a configuration without loading the entire record