See: Description
Interface | Description |
---|---|
RecordWorkflowAction |
Executes custom logic on a record during object workflow events; takes a
RecordWorkflowActionContext as input. |
RecordWorkflowActionContext |
Contains contextual information about an active object workflow during execution.
|
RecordWorkflowActionTaskContext |
Provides methods to update and retrieve information for tasks of an active workflow.
|
WorkflowConfiguration |
Represents the configured workflow definition.
|
WorkflowInstance |
Represents a runtime instance of a workflow.
|
WorkflowInstanceService |
Provides methods to retrieve information for and update workflow instances.
|
WorkflowParticipantGroup |
Provides methods to retrieve information for a participant group of an active workflow.
|
WorkflowParticipantGroupUpdate |
Sets the information needed to perform updates for a
WorkflowParticipantGroup of an active workflow. |
WorkflowTaskChange |
Represents a workflow task that is bring modified.
|
WorkflowTaskConfiguration |
Contains information about the workflow task step configuration.
|
WorkflowTaskInstance |
Represents a workflow task instance created from execution of a task step.
|
WorkflowTaskQueryParameters |
Provides a mechanism to filter workflow task instances.
|
WorkflowTaskService |
Provides methods to retrieve and perform updates for tasks of an active workflow.
|
Enum | Description |
---|---|
WorkflowEvent |
Events surrounding workflow execution.
|
WorkflowStepType |
Types of steps that can exist in a workflow.
|
WorkflowTaskStatus |
Statuses a workflow task instance can be in.
|
Annotation Type | Description |
---|---|
RecordWorkflowActionInfo |
Indicates a class is a
RecordWorkflowAction that can be executed against a workflow for an object record. |
You can configure a custom action for object workflows on any of the following steps:
WorkflowEvent
.
A record workflow action is a Java class that implements the RecordWorkflowAction
interface and has the
@RecordWorkflowActionInfo
annotation.
The RecordWorkflowActionInfo
annotation has the following elements:
label
: Label of the actionobject
: If specified, the action is only available for object workflows associated to the
specified object. If omitted, the action is available across all object workflows.stepTypes
: The workflow step types that this action can be configured against.
During the GET_PARTICIPANTS
event, the code in this example action populates the participant group for the
configured participant control with 2 specific users. After the workflow has been created, firing the AFTER_CREATE
event, the action sends a notification to each user who has been added to the participant group.
@RecordWorkflowActionInfo(label="Custom Approver", object="product__v", stepTypes={WorkflowStepType.START})
public class CustomApprover implements RecordWorkflowAction { public void execute(RecordWorkflowActionContext context) { WorkflowEvent event = context.getEvent(); WorkflowInstance workflowInstance = context.getWorkflowInstance(); WorkflowInstanceService workflowInstanceService = ServiceLocator.locate(WorkflowInstanceService.class); WorkflowParticipantGroup participantGroup = context.getParticipantGroup(); if (event == WorkflowEvent.GET_PARTICIPANTS) { getParticipants(workflowInstanceService, participantGroup); } else if (event == WorkflowEvent.AFTER_CREATE) { afterCreate(workflowInstance, participantGroup); } } private void getParticipants(WorkflowInstanceService workflowInstanceService, WorkflowParticipantGroup participantGroup) { Set<String> users = VaultCollections.newSet(); users.add("1000000"); users.add("1000001"); WorkflowParticipantGroupUpdate participantGroupUpdate = workflowInstanceService.newParticipantGroupUpdate(participantGroup) .setUsers(users); workflowInstanceService.updateParticipantGroup(participantGroupUpdate); } private void afterCreate(WorkflowInstance workflowInstance, WorkflowParticipantGroup participantGroup) { NotificationService notificationService = ServiceLocator.locate(NotificationService.class); String processInstanceId = workflowInstance.getId(); Set<String> participantUserIds = participantGroup.getUsers(); String participantGroupLabel = participantGroup.getLabel(); NotificationParameters parameters = notificationService.newNotificationParameters() .setRecipientsByUserIds(participantUserIds); String notificationText = "You were added to the participant group \"" + participantGroupLabel + "\" of workflow " + processInstanceId; NotificationMessage message = notificationService.newNotificationMessage() .setSubject("A new workflow started") .setMessage(notificationText) .setNotificationText(notificationText); notificationService.send(parameters, message); } }
TASK_AFTER_CREATE
event, the action logs information for the created task instances.TASK_AFTER_COMPLETE
event, the action cancels all other outstanding task instances for
the current task step.TASK_AFTER_CANCEL
event, the action sends a notification to the assignees of each cancelled
task instance.TASK_AFTER_ASSIGN
event, the action logs information for the tasks that have been either
reassigned or accepted.@RecordWorkflowActionInfo(label="Approver Task Action", object="product__v", stepTypes={WorkflowStepType.TASK})
public class ApproverTaskAction implements RecordWorkflowAction { public void execute(RecordWorkflowActionContext context) { WorkflowEvent taskEvent = context.getEvent(); if (taskEvent == WorkflowEvent.TASK_AFTER_CREATE) { handleCreate(context); } else if (taskEvent == WorkflowEvent.TASK_AFTER_COMPLETE) { handleComplete(context); } else if (taskEvent == WorkflowEvent.TASK_AFTER_CANCEL) { handleCancel(context); } else if (taskEvent == WorkflowEvent.TASK_AFTER_ASSIGN) { handleAssign(context); } } private void handleCreate(RecordWorkflowActionContext context) { LogService logger = ServiceLocator.locate(LogService.class); RecordWorkflowActionTaskContext taskContext = context.getTaskContext(); WorkflowTaskConfiguration taskConfiguration = taskContext.getTaskConfiguration(); String participantGroupLabel = taskConfiguration.getParticipantGroupLabel(); List<WorkflowTaskChange> createdTaskChanges = taskContext.getTaskChanges(); logger.info(createdTaskChanges.size() + " tasks have been created for " + "participant group " + participantGroupLabel); for (WorkflowTaskChange taskChange : createdTaskChanges) { WorkflowTaskInstance createdTaskInstance = taskChange.getNew(); String taskId = createdTaskInstance.getId(); String assigneeId = createdTaskInstance.getAssigneeId(); logger.info("Task " + taskId + " has been created for user " + assigneeId); } } private void handleComplete(RecordWorkflowActionContext context) { WorkflowTaskService workflowTaskService = ServiceLocator.locate(WorkflowTaskService.class); WorkflowInstance workflowInstance = context.getWorkflowInstance(); RecordWorkflowActionTaskContext taskContext = context.getTaskContext(); WorkflowTaskConfiguration taskConfiguration = taskContext.getTaskConfiguration(); WorkflowTaskInstance completedTaskInstance = taskContext.getTaskChanges().get(0).getNew(); // Find all outstanding task instances (assigned or available) for the current task step WorkflowTaskQueryParameters queryParameters = workflowTaskService.newWorkflowTaskQueryParameters() .setStatuses(WorkflowTaskStatus.ASSIGNED, WorkflowTaskStatus.AVAILABLE) .setTaskConfigurations(taskConfiguration); List<WorkflowTaskInstance> openTaskInstancesForTask = workflowTaskService.getTaskInstances(workflowInstance, queryParameters); // Cancel all other outstanding task instances for the current task step List<WorkflowTaskInstance> tasksToCancel = VaultCollections.newList(); for (WorkflowTaskInstance taskInstance : openTaskInstancesForTask) { if (taskInstance.getId() != completedTaskInstance.getId()) { tasksToCancel.add(taskInstance); } } if (!tasksToCancel.isEmpty()) { workflowTaskService.cancel(workflowInstance, tasksToCancel); } } private void handleCancel(RecordWorkflowActionContext context) { RecordWorkflowActionTaskContext taskContext = context.getTaskContext(); String taskLabel = taskContext.getTaskConfiguration().getLabel(); List<WorkflowTaskChange> cancelledTaskChanges = taskContext.getTaskChanges(); String workflowLabel = context.getWorkflowConfiguration().getLabel(); NotificationService notificationService = ServiceLocator.locate(NotificationService.class); Set<String> recipients = VaultCollections.newSet(); for (WorkflowTaskChange taskChange : cancelledTaskChanges) { WorkflowTaskInstance cancelledTaskInstance = taskChange.getNew(); String assigneeId = cancelledTaskInstance.getAssigneeId(); recipients.add(assigneeId); } NotificationParameters parameters = notificationService.newNotificationParameters() .setRecipientsByUserIds(recipients); String notificationText = "Task \"" + taskLabel + "\" was cancelled for workflow \"" + workflowLabel + "\"."; NotificationMessage message = notificationService.newNotificationMessage() .setSubject(notificationText) .setMessage(notificationText) .setNotificationText(notificationText); notificationService.send(parameters, message); } private void handleAssign(RecordWorkflowActionContext context) { RecordWorkflowActionTaskContext taskContext = context.getTaskContext(); WorkflowTaskChange taskChange = taskContext.getTaskChanges().get(0); WorkflowTaskInstance newTaskInstance = taskChange.getNew(); WorkflowTaskInstance oldTaskInstance = taskChange.getOld(); WorkflowTaskStatus newTaskStatus = newTaskInstance.getStatus(); WorkflowTaskStatus oldTaskStatus = oldTaskInstance.getStatus(); String taskId = newTaskInstance.getId(); String oldAssigneeId = newTaskInstance.getAssigneeId(); String newAssigneeId = oldTaskInstance.getAssigneeId(); LogService logger = ServiceLocator.locate(LogService.class); if ((oldTaskStatus == WorkflowTaskStatus.ASSIGNED) && (newTaskStatus == WorkflowTaskStatus.ASSIGNED)) { logger.info("Task " + taskId + " has been reassigned from user " + oldAssigneeId + " to " + "user " + newAssigneeId); } else if ((oldTaskStatus == WorkflowTaskStatus.AVAILABLE) && (newTaskStatus == WorkflowTaskStatus.ASSIGNED)) { logger.info("Task " + taskId + " has been accepted by user " + newAssigneeId); } } }
Copyright © Veeva Systems 2017–2019. All rights reserved.