Zum Hauptinhalt springen

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

ParameterTypeDescription
configNameStringThe name of the configuration that contains the record
recordIdNumberThe ID of the record that contains the attachment
fileNameStringThe 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");
}
  • loadConfigRecordById() - For loading a complete config record by its ID
  • getAttachmentId() - Similar function for regular app records
  • getAttachmentById() - For retrieving the actual attachment content using its ID
  • downloadAttachment() - For downloading an attachment using its ID
  • getConfigRecordById() - 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