如何通过Acumatica WebService获取案例活动的文件附件与备注
Hey there! Let’s figure out how to pull Case Activities along with their File Attachments and Notes via Acumatica’s Web Service— I’ve walked through this with a few folks before, so here’s the most reliable approach I’ve found:
First, a quick recap of how Acumatica structures these entities:
- Case Activities map to the
CRCaseActivityentity - Notes are stored in
CRNote, linked to activities via theRefNoteID(matching the activity'sNoteID) andRefTypeset toCRCaseActivity - File Attachments live in the
Fileentity, each tied to aCRNotevia theNoteIDfield
1. Contract-Based OData API (Recommended)
This is Acumatica’s modern, flexible API option— way easier for fetching related data in one go.
Step 1: Enable Entities
First, make sure your Acumatica instance has OData enabled for CRCaseActivity, CRNote, and File entities. You can set this up in a customization project under Web Service Settings.
Step 2: Fetch Activities + Notes + Attachments in One Query
Use the $expand parameter to load nested related data. Here’s how to target a specific case:
GET /entity/Default/[YourAcumaticaVersion]/CRCaseActivity?$filter=CaseID eq 'CASE000123'&$expand=Notes($expand=Files)
Replace [YourAcumaticaVersion] with your instance’s version (e.g., 23.200.001 for 2023 R2). This query will return:
- All activities for the case
CASE000123 - Every note linked to each activity
- Every file attachment linked to those notes
Step 3: Filter or Select Specific Fields
If you don’t need all fields, add $select to slim down the response:
GET /entity/Default/23.200.001/CRCaseActivity?$filter=CaseID eq 'CASE000123'&$select=CaseID,ActivityID,Subject&$expand=Notes($select=NoteText,NoteID;$expand=Files($select=FileName,FileID))
2. SOAP API (Legacy Approach)
If you’re still using the traditional SOAP API, you’ll need to chain queries to pull related data:
Example C# Code
using(var context = new DefaultSoapClient()) { // Login to the service context.Login("yourUsername", "yourPassword", null, null, null); // 1. Fetch activities for a specific case var activityQuery = new CRCaseActivity { CaseID = new StringSearch { Value = "CASE000123" }, // Include placeholder for notes to trigger join Notes = new CRNote[] { new CRNote { NoteID = new GuidSearch() } } }; var activities = context.GetList(activityQuery, new[] { "CaseID", "ActivityID", "Subject", "Notes/NoteID", "Notes/NoteText" }); // 2. For each activity's note, fetch linked files foreach(var activity in activities) { if(activity.Notes != null) { foreach(var note in activity.Notes) { var fileQuery = new File { NoteID = new GuidSearch { Value = note.NoteID.Value } }; var attachments = context.GetList(fileQuery, new[] { "FileName", "FileID", "Url" }); // Process your attachments here foreach(var file in attachments) { Console.WriteLine($"Attached file: {file.FileName}"); } } } } // Logout context.Logout(); }
Common Troubleshooting Tips
- Permissions: Double-check that your web service user has Read access to
CRCaseActivity,CRNote, andFileentities, plus data access to the specific cases you’re querying. - Entity Linkage: Ensure you’re using the correct fields:
CRNote.RefTypemust equalCRCaseActivity, andCRNote.RefNoteIDmatchesCRCaseActivity.NoteID. - Version Mismatch: For OData, confirm your endpoint version matches your Acumatica instance (e.g.,
22.200.001for 2022 R2).
If you can share the specific errors or code snippets you tried earlier, I can help narrow down exactly where things went wrong!
内容的提问来源于stack exchange,提问作者Krunal

