NoteAndAttachment Class Reference
The NoteAndAttachment class represents notes, file attachments, bookmarks, and code snippets that can be linked to any record in the Magentrix platform. This class provides a unified way to attach content to entities such as Accounts, Contacts, Opportunities, and custom entities.
Overview
The NoteAndAttachment class is used to create four types of content attached to records:
- Notes - Text-based notes and comments
- File Attachments - Files attached to records
- Bookmarks - Links to external URLs attached to records
- Snippets - Code snippets and configuration files attached to records
Key Characteristics:
- Single class for multiple content types (Type property determines behavior)
- Links to parent records via ReferenceId property
- Support for file uploads via Load() static method
- Automatic file storage handling via FileContents property
- Visible in record's Notes & Attachments section
NoteAndAttachment vs Document:
- NoteAndAttachment = Content attached to specific records (via ReferenceId)
- Document = Content organized in Document Library folders (via FolderId)
- Different use cases and visibility in the platform
NoteAndAttachment Types
The Type property determines the content type:
| Type Value | Type Name | Description | Use Case |
|---|
0 | Note | Text-based note | Comments, descriptions, meeting notes |
1 | File Attachment | Uploaded file | PDFs, images, documents attached to records |
2 | Bookmark | External URL link | Links to external resources for a record |
3 | Snippet | Code snippet or configuration file | JavaScript, C#, CSS, JSON, XML, SQL code attached to records |
NoteAndAttachment Properties Reference
Core Properties
| Property | Type | Required | Description |
|---|
| Id | string | Auto | System-generated unique identifier (read-only) |
| Name | string | Yes | Display name for the note/attachment/bookmark/snippet |
| Type | int | Yes | Content type: 0 = Note, 1 = File, 2 = Bookmark, 3 = Snippet |
| ReferenceId | string | Yes | ID of the parent record this content is attached to |
| Body | string | Varies | Content based on Type (see below) |
Body Property Usage by Type
| Type | Body Contains | Example |
|---|
| Note (0) | Note text content | "Meeting notes from client call..." |
| File (1) | File description | "Q4 Financial Report" |
| Bookmark (2) | URL | "https://example.com/resource" |
| Snippet (3) | Code or configuration text | "function calculate() { return x + y; }" |
File-Specific Properties
| Property | Type | Required | Description |
|---|
| FileContents | string | For files | Base64-encoded file content (automatically handled by Load()) |
| ContentType | string | For files | MIME type (e.g., "application/pdf", "image/png") |
System Fields
| Property | Type | Required | Description |
|---|
| CreatedOn | DateTime | Auto | Record creation timestamp (read-only) |
| CreatedById | string | Auto | User ID who created the record (read-only) |
| ModifiedOn | DateTime | Auto | Last modification timestamp (read-only) |
| ModifiedById | string | Auto | User ID who last modified (read-only) |
Static Methods Reference
| Method | Return Type | Description |
|---|
| Load(HttpPostedFile file) | NoteAndAttachment | Creates NoteAndAttachment from uploaded file with auto-populated properties |
NoteAndAttachment.Load() Method
Creates a NoteAndAttachment object from an uploaded file with properties automatically populated.
Signature:
static NoteAndAttachment Load(HttpPostedFile file)
Parameters:
file (HttpPostedFile, required) - The uploaded file from aspx:FieldFileUpload
Returns:
- NoteAndAttachment object with populated properties, or null if file is empty
Auto-Populated Properties:
Name - Original filenameType - Automatically set to 1 (File Attachment)ContentType - MIME type from uploaded fileFileContents - Base64-encoded file content
Properties You Must Set:
ReferenceId - ID of the parent record
Property Details
Type
Determines the content type of the NoteAndAttachment record.
Type: int
Required: Yes
Valid Values:
0 - Note (text content)1 - File Attachment2 - Bookmark (URL)3 - Snippet (code or configuration file)
Description: The Type property controls how the platform interprets and displays the NoteAndAttachment record. Different types use the Body and other properties differently.
Body
Multi-purpose content field used differently based on Type.
Type: string
Required: Yes (except file description is optional)
Usage by Type:
For Notes (Type = 0):
- Contains the note text content
- Supports plain text and rich text
- No length limit (within reasonable database constraints)
For File Attachments (Type = 1):
- Contains optional file description or comments
- Not the file content itself (use FileContents for file data)
- Descriptive text about the file
For Bookmarks (Type = 2):
- Contains the URL string
- Must be valid URL format (http:// or https://)
- Max 2000 characters
For Snippets (Type = 3):
- Contains the code or configuration file content
- Plain text format
- Common snippet types: JavaScript (.js), C# (.cs), CSS (.css), JSON (.json), XML (.xml), SQL (.sql), HTML (.html)
- Used for storing code samples, configuration files, and script fragments
ReferenceId
ID of the parent record to which this content is attached.
Type: string
Required: Yes
Description: Links the NoteAndAttachment to a specific parent record. Content appears in the Notes & Attachments section of that record's detail page.
Usage:
- Set to any valid record ID in the system
- Commonly used with: Account, Contact, Opportunity, Case, custom entities
- Must be valid existing record ID
- Cannot be null or empty
FileContents
Base64-encoded file content for file attachments.
Type: string
Required: Only when Type = 1 (file attachments)
Description: Contains the actual file data encoded as a Base64 string. When a file is uploaded, its bytes are converted to Base64 and stored in this property.
Automatic Population:
- Automatically set when using Load() method
- Handles encoding internally
- No manual encoding needed when using Load()
Important Notes:
- Only relevant for Type = 1 (file attachments)
- Ignored for Types 0, 2, 3
- Maximum file size subject to platform limits
ContentType
MIME type of the attached file.
Type: string
Required: Recommended for Type = 1
Description: Specifies the MIME type of the file attachment. Used by browsers to determine how to handle file downloads.
Common MIME Types:
"application/pdf" - PDF documents"application/vnd.openxmlformats-officedocument.wordprocessingml.document" - Word (.docx)"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" - Excel (.xlsx)"image/png" - PNG images"image/jpeg" - JPEG images"text/plain" - Text files
Automatic Population:
- Automatically set when using Load() method
- Extracted from uploaded file's content type
Snippet Usage (Type = 3)
Snippets are code files and configuration content attached to records for development, configuration, and technical documentation purposes.
Properties for Snippets:
Name - Snippet filename or identifier (e.g., "validation.js", "config.json")Body - Code or configuration contentType - Set to 3ReferenceId - Parent record ID
Common Snippet File Types:
- JavaScript (.js) - JavaScript code snippets and functions
- C# (.cs) - C# code samples and class definitions
- CSS (.css) - Stylesheet snippets and style definitions
- JSON (.json) - Configuration files and data structures
- XML (.xml) - XML configuration and data files
- SQL (.sql) - SQL queries and database scripts
- HTML (.html) - HTML markup snippets
- TypeScript (.ts) - TypeScript code snippets
- Python (.py) - Python code samples
- YAML (.yaml/.yml) - YAML configuration files
Use Cases:
- Code samples for integration documentation
- Configuration file templates
- SQL query libraries attached to projects
- JavaScript functions for custom implementations
- CSS style overrides for customizations
- API request/response examples in JSON
- Script fragments for automation
Snippet vs Document Snippet:
| Feature | NoteAndAttachment Snippet | Document Snippet |
|---|
| Type | 3 (int) | "Snippet" (string) |
| Storage | Attached to records (ReferenceId) | Document Library folders (FolderId) |
| Extension field | Not used | Required (js, css, html, etc.) |
| ContentType field | Not used | "Snippet" |
| UniqueName field | Not used | Required |
| Use Case | Code/config attached to specific records | Code/config organized in Document Library |
| Body persistence | Persisted in database | Transient (stored in cloud storage) |
Related Topics