Alfresco SDK 3:如何访问表单中未显示的变量
Hey there! Let's break down how to get those hidden form variables from your wfvd:activitiReviewTask type defined in workflow-validation-model.xml. These variables are actually custom properties on the Alfresco task node (since your type extends wf:activitiReviewTask, a subtype of bpm:workflowTask), so we'll need to interact with Alfresco's core services to fetch them.
1. Backend Approach (Java Code)
If you're working in a Java delegate, web script, or any backend component in your SDK 3 project, here's how to access the properties:
Step 1: Inject Required Services
First, autowire the core services needed to link the Activiti task to its Alfresco node and read properties:
@Autowired private NodeService nodeService; @Autowired private TaskService taskService;
Step 2: Fetch the Task Node Reference
Every Activiti task in Alfresco is tied to a bpm:workflowTask node. Use the task ID to retrieve this node's NodeRef:
// Replace with your actual task ID (you can get this from DelegateExecution or task queries) String taskId = "your-task-uuid-here"; NodeRef taskNodeRef = (NodeRef) taskService.getVariable(taskId, "bpm:workflowTask");
Step 3: Read the Hidden Properties
Define the QName for each property (matching your model's namespace) and fetch their values:
// Replace with your model's namespace URI (check workflow-validation-model.xml for this) String WFVD_NAMESPACE = "http://your-namespace-uri/model/workflowvalidation/1.0"; QName retourMedecinQName = QName.createQName(WFVD_NAMESPACE, "retourMedecin"); QName nomServiceQName = QName.createQName(WFVD_NAMESPACE, "nomService"); QName newPatientQName = QName.createQName(WFVD_NAMESPACE, "newPatient"); // Retrieve property values (adjust types based on your model definitions) String retourMedecin = (String) nodeService.getProperty(taskNodeRef, retourMedecinQName); String nomService = (String) nodeService.getProperty(taskNodeRef, nomServiceQName); Boolean newPatient = (Boolean) nodeService.getProperty(taskNodeRef, newPatientQName); // Use the values as needed System.out.println("Retour médecin: " + retourMedecin);
2. Frontend/REST Approach
If you need to access these variables from a Share custom page or external app, use Alfresco's REST API:
- First, fetch the task details via
GET /alfresco/api/-default-/public/alfresco/versions/1/workflow-tasks/{taskId}to get thenodeIdfield (this is the ID of the linkedbpm:workflowTasknode) - Then call the node properties endpoint to retrieve all properties, including hidden ones:
GET /alfresco/api/-default-/public/alfresco/versions/1/nodes/{task-node-id}/properties
Key Notes
- Namespace Check: Double-check the namespace URI in your
workflow-validation-model.xml(look for the<namespace>tag) — this must match what you use in yourQNamedefinitions. - Model Deployment: Ensure your model is properly loaded in your SDK 3 project. Add this bean to your
service-context.xml(underplatform-jar/src/main/resources/alfresco/module/platform-jar/context/):<bean id="workflowValidationModel" parent="dictionaryModel"> <property name="location" value="classpath:alfresco/module/platform-jar/model/workflow-validation-model.xml"/> </bean> - Task ID Retrieval: If you don't have the task ID upfront, use
TaskService.createTaskQuery()to filter tasks by process instance ID, assignee, or other criteria.
内容的提问来源于stack exchange,提问作者anakin59490

