Package com.veeva.vault.sdk.api.lifecycle
package com.veeva.vault.sdk.api.lifecycle
This package provides interfaces to retrieve configuration metadata for object and document lifecycles and actions, and to execute actions.
Object Lifecycle User Action Services
TheObjectLifecycleStateUserActionMetadataService provides methods to
retrieve configuration metadata about user actions, while
ObjectLifecycleStateUserActionService provides methods to execute those
actions.
Example: Retrieving configuration metadata about Lifecycle User Actions
The following example illustrates how to retrieve configuration metadata about available lifecycle user actions.
ObjectLifecycleStateUserActionMetadataService service = ServiceLocator.locate(ObjectLifecycleStateUserActionMetadataService.class);
LogService logService = ServiceLocator.locate(LogService.class);
// Retrieve metadata about user actions on a particular lifecycle state
// Build the metadata request
ObjectLifecycleUserActionMetadataRequest request = service.newLifecycleUserActionMetadataRequestBuilder()
.withLifecycleName(lifecycleName)
.withLifecycleState(lifecycleState)
.withActionType("LIFECYCLE_RUN_WORKFLOW_ACTION") // Optional: filter the type of the user actions to be returned
.build();
ObjectLifecycleUserActionCollectionResponse response = service.getLifecycleUserActions(request);
List<ObjectLifecycleUserActionMetadata> userActionMetadata = response.getUserActions();
for (ObjectLifecycleUserActionMetadata data : userActionMetadata) {
logService.info("User action metadata: label {}, component name {}, user action name {}," +
"type {}, workflow name {}, record action class name {}, fully qualified name {}",
data.getLabel(), data.getName(), data.getUserActionName(), data.getType(),
data.getWorkflowName(), data.getRecordActionClassName(), data.getFullyQualifiedActionName());
}
// Retrieve metadata about user actions on an object record
// Build the metadata request
ObjectRecordLifecycleUserActionMetadataRequest request = service.newRecordLifecycleUserActionMetadataRequestBuilder()
.withObjectName("object__c")
.withRecordId("V6U000000001001")
.withLifecycleState("inactive_state__c") // Optional: set the lifecycle state for the record, otherwise use the state the record is currently on
.build();
ObjectRecordLifecycleUserActionCollectionResponse response = service.getRecordLifecycleUserActions(request);
List<ObjectRecordLifecycleUserActionDetail> details = response.getUserActions();
for (ObjectRecordLifecycleUserActionDetail detail : details) {
logService.info("User action is executable {}, is viewable {}", detail.isExecutable(), detail.isViewable());
ObjectLifecycleUserActionMetadata metadata = detail.getMetadata();
logService.info("User action metadata: label {}, component name {}, ...",
metadata.getLabel(), metadata.getName());
}
Example: Retrieving input parameter metadata for user actions
The following example illustrates how to retrieve and use input parameter metadata for user actions. This service returns metadata aboutRecordActions annotated with a
user_input_object, configured as a user action.
ObjectLifecycleStateUserActionService service = ServiceLocator.locate(ObjectLifecycleStateUserActionService.class);
// Build the request
ObjectLifecycleUserActionInputParameterMetadataRequest request = service.newInputParameterMetadataRequestBuilder()
.withUserActionName("Objectlifecyclestateuseraction.object__c.active_state__c.action__c")
.build();
ObjectLifecycleUserActionInputParameterMetadata metadata = service.getInputParameterMetadata(request);
// Get the metadata for the input parameter
String userInputObjectName = metadata.getUserInputObjectName();
String userInputObjectType = metadata.getUserInputObjectTypeName():
// Use the metadata to create a record of that object
Record input = recordService.newRecord(userInputObjectName);
input.setValue("name__v", "new name");
input.setValue("field__c", "new value");
RecordBatchSaveRequest saveRequest = recordService.newRecordBatchSaveRequestBuilder()
.withRecords(VaultCollections.asList(input))
.build();
recordService.batchSaveRecords(saveRequest)
.rollbackOnErrors()
.execute();
String userInputObjectRecordId = input.getValue(RECORD_ID, ValueType.STRING);
// Use the userInputObjectRecordId to build a request to execute an action with an input
UserActionExecutionRequest request = userActionService.newExecutionRequestBuilder()
.withObjectName("object__c")
.withObjectRecordId("V6U000000001001")
.withUserInputRecordId(userInputObjectRecordId)
.withUserActionName("Objectaction.object__c.action__c") // Use the fully qualified name of the action
.build();
Example: Executing a Lifecycle User Action
The following example illustrates how to execute an action. An action can be a user action, such as a state change, or an object action that is either available on all lifecycle states or configured on a particular state.
The UserActionExecutionRequest.Builder is used to construct the request,
which is submitted in a UserActionExecutionRequest.
Optionally, you can specify success and error handlers on the
UserActionExecutionOperation before execution.
ObjectLifecycleStateUserActionService userActionService = ServiceLocator.locate(ObjectLifecycleStateUserActionService.class);
LogService logService = ServiceLocator.locate(LogService.class);
// Build user action execution request for the record
UserActionExecutionRequest request = userActionService.newExecutionRequestBuilder()
.withObjectName("object__c")
.withObjectRecordId("V6U000000001001")
.withUserInputRecordId(userInputObjectRecordId) // Optional: if the user action is a RecordAction annotated with a user_input_object.
.withUserActionName("Objectaction.object__c.action__c") // Use the fully qualified name of the action.
.build();
// Execute the user action
userActionService.executeUserAction(request)
.onSuccess(userActionExecutionResponse -> {
// Logic to be executed if the user action completes successfully.
logService.info("Successfully executed user action");
})
.onError(error -> {
// Logic to be executed if the user action encounters an error when executing.
if (error.getErrorType().equals(ActionErrorType.PERMISSION_DENIED)) {
logService.error("Failed to execute user action: " + error.getMessage());
}
})
.execute();
Document Lifecycle User Action Services
TheDocumentLifecycleStateUserActionMetadataService provides methods to
retrieve configuration metadata about user actions, while
DocumentLifecycleStateUserActionService provides methods to execute those
actions.
Example: Retrieving configuration metadata about Lifecycle User Actions
The following example illustrates how to retrieve configuration metadata about available lifecycle user actions.
DocumentLifecycleStateUserActionMetadataService service = ServiceLocator.locate(DocumentLifecycleStateUserActionMetadataService.class);
LogService logService = ServiceLocator.locate(LogService.class);
// Retrieve metadata about user actions on a particular lifecycle state
// Build the metadata request
DocumentLifecycleUserActionMetadataRequest request = service.newUserActionRequestBuilder()
.withLifecycleName(lifecycleName)
.withStateName(lifecycleState)
.build();
DocumentLifecycleUserActionMetadataResponse response = service.getUserActions(request);
List<DocumentLifecycleUserActionMetadata> userActionMetadata = response.getUserActions();
for (DocumentLifecycleUserActionMetadata data : userActionMetadata) {
logService.info("User action metadata: label {}, user action name {}," +
"workflow name {}, document action class name {}",
data.getLabel(), data.getUserActionName(),
data.getWorkflowName(), data.getDocumentActionClassName());
}
// Retrieve metadata about user actions on a document version
// Build the metadata request
DocumentVersionLifecycleUserActionMetadataRequest request = service.newDocumentVersionUserActionRequestBuilder()
.withDocumentVersionId("1_2_3")
.build();
DocumentVersionLifecycleUserActionMetadataResponse response = service.getDocumentVersionUserActions(request);
List<DocumentVersionLifecycleUserActionDetail> details = response.getUserActions();
for (DocumentVersionLifecycleUserActionDetail detail : details) {
logService.info("User action is executable {}, is viewable {}", detail.isExecutable(), detail.isViewable());
DocumentLifecycleUserActionMetadata metadata = detail.getMetadata();
logService.info("User action metadata: label {}, user action name {}, ...",
metadata.getLabel(), metadata.getUserActionName());
}
Example: Retrieving input metadata for user actions
The following example illustrates how to retrieve and use input metadata for user actions. This service returns metadata aboutDocumentActions annotated with a
user_input_object.
DocumentLifecycleStateUserActionMetadataService service = ServiceLocator.locate(DocumentLifecycleStateUserActionMetadataService.class);
// Build the request
DocumentLifecycleUserActionUserInputMetadataRequest request = service.newUserInputRequestBuilder()
.withUserActionName("sdkDocLifecycleUA134c9hshe71tc__c")
.build();
DocumentLifecycleUserActionUserInputMetadata metadata = service.getUserInput(request);
// Get the metadata for the input
String userInputObjectName = metadata.getUserInputObjectName();
String userInputObjectType = metadata.getUserInputObjectTypeName():
// Use the metadata to create a record of that object
Record input = recordService.newRecord(userInputObjectName);
input.setValue("name__v", "new name");
input.setValue("field__c", "new value");
RecordBatchSaveRequest saveRequest = recordService.newRecordBatchSaveRequestBuilder()
.withRecords(VaultCollections.asList(input))
.build();
recordService.batchSaveRecords(saveRequest)
.rollbackOnErrors()
.execute();
String userInputObjectRecordId = input.getValue(RECORD_ID, ValueType.STRING);
// Use the userInputObjectRecordId to build a request to execute an action with an input
DocumentLifecycleUserActionExecutionRequest request = documentLifecycleStateUserActionService.newExecutionRequestBuilder()
.withDocumentVersionId("1_2_3")
.withUserInputRecordId(userInputObjectRecordId)
.withUserActionName("sdkDocLifecycleUA134c9hshe71tc__c")
.build();
Example: Executing a Lifecycle User Action
The following example illustrates how to execute an action.
The DocumentLifecycleUserActionExecutionRequest.Builder is used to construct the request,
which is submitted in a DocumentLifecycleUserActionExecutionRequest.
Optionally, you can specify success and error handlers on the
DocumentLifecycleUserActionExecutionOperation before execution.
DocumentLifecycleStateUserActionService userActionService = ServiceLocator.locate(DocumentLifecycleStateUserActionService.class);
LogService logService = ServiceLocator.locate(LogService.class);
// Build user action execution request for the document version
DocumentLifecycleUserActionExecutionRequest request = userActionService.newExecutionRequestBuilder()
.withDocumentVersionId("1_2_3")
.withUserInputRecordId(userInputObjectRecordId) // Optional: if the user action is a DocumentAction annotated with a user_input_object.
.withUserActionName("sdkDocLifecycleUA134c9hshe71tc__c")
.build();
// Execute the user action
userActionService.executeUserAction(request)
.onSuccess(userActionExecutionResponse -> {
// Logic to be executed if the user action completes successfully.
logService.info("Successfully executed user action");
})
.onError(error -> {
// Logic to be executed if the user action encounters an error when executing.
if (error.getErrorType().equals(ActionErrorType.PERMISSION_DENIED)) {
logService.error("Failed to execute user action: " + error.getMessage());
}
})
.execute();
-
ClassDescriptionError types that can occur during SDK action execution.Provides methods to retrieve metadata fields for a specific document lifecycle.Represents a request to retrieve multiple document lifecycles in the format of
DocumentLifecycleMetadatacollection.Creates an instance ofDocumentLifecycleMetadataRequest.Holds aDocumentLifecycleMetadatacollection.Provides methods to retrieve document lifecycle, state, stage group, stage, and role metadata.Provides methods to retrieve metadata fields for a specific document lifecycle role.Represents a request to retrieve multiple document lifecycle roles in the format ofDocumentLifecycleRoleMetadatacollection.Creates an instance ofDocumentLifecycleRoleMetadataRequest.Holds aDocumentLifecycleRoleMetadatacollection.Provides methods to retrieve metadata fields for a specific document lifecycle stage group.Represents a request to retrieve multiple document lifecycle stage groups in the format ofDocumentLifecycleStageGroupMetadatacollection.Creates an instance ofDocumentLifecycleStageGroupMetadataRequest.Holds aDocumentLifecycleStageGroupMetadatacollection.Provides methods to retrieve metadata fields for a specific document lifecycle stage.Represents a request to retrieve multiple document lifecycle stages in the format ofDocumentLifecycleStageMetadatacollection.Creates an instance ofDocumentLifecycleStageMetadataRequest.Holds aDocumentLifecycleStageMetadatacollection.Container for input parameters necessary to execute a Run Workflow document lifecycle user action.Creates an instance ofDocumentLifecycleStartWorkflowInputParameter.Provides methods to retrieve metadata fields for a specific document lifecycle state.Represents a request to retrieve multiple document lifecycle states in the format ofDocumentLifecycleStateMetadatacollection.Creates an instance ofDocumentLifecycleStateMetadataRequest.Holds aDocumentLifecycleStateMetadatacollection.Provides methods to retrieve metadata about document lifecycle user action, document version lifecycle user action, and user action user input.Provides methods to execute a document lifecycle user action.Represents an error encountered during aDocumentLifecycleUserActionExecutionOperation.A sequence of instructions that can be chained together, building a document lifecycle user action execution operation that can be executed withDocumentLifecycleUserActionExecutionOperation.execute().Provides methods to set the parameters necessary to execute a document lifecycle user action.Creates an instance ofDocumentLifecycleUserActionExecutionRequest.Represents the result of the execution of a document lifecycle user action.Provides methods to retrieve metadata fields for a specific document lifecycle user action.Represents a request to retrieve metadata about document lifecycle user actions in the format ofDocumentLifecycleUserActionMetadataResponse.Creates an instance ofDocumentLifecycleUserActionMetadataRequest.Holds aDocumentLifecycleUserActionMetadatacollection.Provides methods to retrieve metadata fields for a specific document action's input.Represents a request to retrieve user action user input metadata, in the format ofDocumentLifecycleUserActionUserInputMetadata.Creates an instance ofDocumentLifecycleUserActionUserInputMetadataRequest.Represents the metadata associated with a lifecycle user action for a particular document version.Represents a request to retrieve metadata about document lifecycle user actions on a specific document version in the format ofDocumentVersionLifecycleUserActionMetadataResponse.Creates an instance ofDocumentVersionLifecycleUserActionMetadataRequest.Holds aDocumentVersionLifecycleUserActionDetailcollection.Provides methods to retrieve metadata fields for a specific object lifecycle.Represents a request to retrieve multiple object lifecycles in the format ofObjectLifecycleMetadatacollection.Creates an instance ofObjectLifecycleMetadataCollectionRequest.Holds anObjectLifecycleMetadatacollection.Represents a request to retrieve a single object lifecycle in the format ofObjectLifecycleMetadata.Creates an instance ofObjectLifecycleMetadataRequest.Provides methods to retrieve object lifecycle, state, state type, stage group, and stage metadata.Provides methods to retrieve metadata fields for a specific object lifecycle role.Represents a request to retrieve multiple object lifecycle roles in the format ofObjectLifecycleRoleMetadatacollection.Creates an instance ofObjectLifecycleRoleMetadataCollectionRequest.Holds anObjectLifecycleRoleMetadatacollection.Represents a request to retrieve a single object lifecycle role in the format ofObjectLifecycleRoleMetadata.Creates an instance ofObjectLifecycleRoleMetadataRequest.Provides methods to retrieve metadata fields for a specific object lifecycle stage group.Represents a request to retrieve multiple object lifecycle stage groups in the format ofObjectLifecycleStageGroupMetadatacollection.Creates an instance ofObjectLifecycleStageGroupMetadataCollectionRequest.Holds anObjectLifecycleStageGroupMetadatacollection.Represents a request to retrieve a single object lifecycle stage group in the format ofObjectLifecycleStageGroupMetadata.Creates an instance ofObjectLifecycleStageGroupMetadataRequest.Provides methods to retrieve metadata fields for a specific object lifecycle stage.Represents a request to retrieve multiple object lifecycle stages in the format ofObjectLifecycleStageMetadatacollection.Creates an instance ofObjectLifecycleStageMetadataCollectionRequest.Holds anObjectLifecycleStageMetadatacollection.Represents a request to retrieve a single object lifecycle stage in the format ofObjectLifecycleStageMetadata.Creates an instance ofObjectLifecycleStageMetadataRequest.Provides methods to retrieve metadata fields for a specific object lifecycle state.Represents a request to retrieve multiple object lifecycle states in the format ofObjectLifecycleStateMetadatacollection.Creates an instance ofObjectLifecycleStateMetadataCollectionRequest.Holds anObjectLifecycleStateMetadatacollection.Represents a request to retrieve a single object lifecycle state in the format ofObjectLifecycleStateMetadata.Creates an instance ofObjectLifecycleStateMetadataRequest.Provides methods to retrieve metadata fields for a specific object lifecycle state type.Represents a request to retrieve multiple object lifecycle state types in the format ofObjectLifecycleStateTypeMetadatacollection.Creates an instance ofObjectLifecycleStateTypeMetadataCollectionRequest.Holds anObjectLifecycleStateTypeMetadatacollection.Represents a request to retrieve a single object lifecycle state type in the format ofObjectLifecycleStateTypeMetadata.Creates an instance ofObjectLifecycleStateTypeMetadataRequest.Provides methods to retrieve metadata about an object lifecycle user action.Provides methods to execute an object lifecycle user action.Holds anObjectLifecycleUserActionMetadatacollection.Provides methods to retrieve metadata fields for a specific object action's input object.Representation of a request to retrieve metadata about user action input parameters, in the format ofObjectLifecycleUserActionInputParameterMetadata.Provides methods to retrieve metadata fields for a specific object lifecycle user action.Representation of a request to retrieve metadata about user actions, in the format ofObjectRecordLifecycleUserActionCollectionResponse.Provides methods to retrieve object lifecycle metadata fields for a specific object record.Represents a request to retrieve the object lifecycle metadata fields of multiple object records in the format ofObjectRecordLifecycleMetadatacollection.Creates an instance ofObjectRecordLifecycleMetadataCollectionRequest.Holds anObjectRecordLifecycleMetadatacollection.Represents a request to retrieve the object lifecycle metadata fields of a single object record in the format ofObjectRecordLifecycleMetadata.Creates an instance ofObjectRecordLifecycleMetadataRequest.Holds anObjectRecordLifecycleUserActionDetailcollection.Represents the metadata associated with a lifecycle user action for a particular record.A sequence of instructions that can be chained together, building a user action execution operation that can be executed withUserActionExecutionOperation.execute().Represents an error encountered during aUserActionExecutionOperation.Provides methods to set the parameters necessary to execute a User Action.Represents the result of the execution of a user action.