如何在Alfresco中查找特定模型文件并展示其字段至表格?
Got it, let's walk through exactly how to find all documents tied to a specific Alfresco model and display their fields in a table. I'll cover both manual (no-code) and programmatic (automated) approaches since both are super common depending on your use case.
If you just need a one-time table and don't want to code, Alfresco Share's built-in tools work perfectly:
- Head to your Alfresco Share instance and click the Advanced Search option (usually accessible via the dropdown next to the top search bar).
- In the advanced search form, look for the Type or Aspect filter. Use the dropdown to select the specific type from your target model (e.g., if your model is
custom:projectDoc, pick that option). - Hit Search to pull up all documents of that type.
- To customize which fields show up in the results: Click the Columns button in the top-right of the results list, then check all the fields (system or custom from your model) you want to include.
- Once your columns are set, you can either copy-paste the results directly into Excel/Google Sheets, or use the Export to CSV option (available in most Share versions) to get a ready-to-use table.
If you need to automate this process (e.g., schedule it, integrate with other tools), the Alfresco REST API is the way to go. Here's a step-by-step breakdown:
Step 1: Authenticate to get a session ticket
First, you need to authenticate to Alfresco to get a valid ticket for subsequent requests. Using curl as an example:
curl -X POST "http://<your-alfresco-host>:<port>/alfresco/api/-default-/public/authentication/versions/1/tickets" \ -H "Content-Type: application/json" \ -d '{"userId":"<your-username>","password":"<your-password>"}'
This will return a JSON response with a ticket value—save this, you'll need it for every other request.
Step 2: Search for documents of your target model
Use the Alfresco Search API to query all documents of your specific model type. Replace the TYPE value with your model's qualified name (e.g., custom:projectDoc) and list the fields you want to retrieve:
curl -X POST "http://<your-alfresco-host>:<port>/alfresco/api/-default-/public/search/versions/1/search" \ -H "Content-Type: application/json" \ -H "Authorization: Basic <your-ticket>" \ -d '{ "query": { "query": "TYPE:\"custom:projectDoc\"" }, "fields": ["cm:name", "cm:created", "cm:creator", "custom:projectId", "custom:documentStatus"], "paging": { "maxItems": 100, "skipCount": 0 } }'
- The
fieldsarray lets you specify exactly which system or custom fields you want to pull for each document. - The
pagingparameters handle large result sets—adjustmaxItemsand incrementskipCountto fetch all pages of results.
Step 3: Parse results and generate a table
The API returns JSON data, so you can use a script (Python, JavaScript, etc.) to parse it and output a table. Here's a quick Python example that generates a Markdown table:
import requests import json # Authenticate to get ticket auth_url = "http://localhost:8080/alfresco/api/-default-/public/authentication/versions/1/tickets" auth_payload = {"userId": "admin", "password": "admin"} auth_response = requests.post(auth_url, json=auth_payload) ticket = auth_response.json()["entry"]["id"] # Execute search search_url = "http://localhost:8080/alfresco/api/-default-/public/search/versions/1/search" headers = {"Authorization": f"Basic {ticket}", "Content-Type": "application/json"} search_payload = { "query": {"query": "TYPE:\"custom:projectDoc\""}, "fields": ["cm:name", "cm:created", "custom:projectId", "custom:documentStatus"], "paging": {"maxItems": 100, "skipCount": 0} } search_response = requests.post(search_url, headers=headers, json=search_payload) documents = search_response.json()["list"]["entries"] # Generate Markdown table if documents: # Extract headers from the first document's fields table_headers = list(documents[0]["entry"].keys()) print("| " + " | ".join(table_headers) + " |") print("| " + " | ".join(["---"] * len(table_headers)) + " |") # Populate table rows for doc in documents: row_values = [str(doc["entry"][header]) for header in table_headers] print("| " + " | ".join(row_values) + " |") else: print("No documents found for the specified model.")
- Make sure you know your model's qualified name (e.g.,
custom:projectDoc). You can find this in the Alfresco Admin Console's Model Manager, or via the REST API's model endpoints. - To fetch all types under a single model, use a wildcard in your query:
TYPE:\"custom:*\". - For very large datasets, loop through pagination pages (increment
skipCountbymaxItemseach time) until you get an empty result set.
内容的提问来源于stack exchange,提问作者Kun Aguero

