Skip navigation links

Package com.veeva.vault.sdk.api.action

This package provides interfaces to create custom actions.

See: Description

Package com.veeva.vault.sdk.api.action Description

This package provides interfaces to create custom actions.

Record Actions

Objects can have custom actions that perform specific instructions. You can use a custom action to automate certain business processes. Custom actions for records, called record actions or record user actions, are invoked by a user on a specific record from the UI or API. Learn more about Object User Actions in Vault Help.

A record action is a Java class that implements the RecordAction interface and has the RecordActionInfo annotation. For example:

   @RecordActionInfo(name="hello__c", label="Say Hello", object="hello_world__c")
 
   public class Hello implements RecordAction {
      public boolean isExecutable(RecordActionContext context) {
          return true;
      }

      public void execute(RecordActionContext context) {
          // Get the current record on which the action is invoked
          List<Record> records = context.getRecords();
          Record record= records.get(0);

          String name = record.getValue("name__v", ValueType.STRING);
          String[] originalName = null;

          if (!StringUtils.matches(name, "Hello(.*)")) {
              record.setValue("name__v","Hello, " + name);
          } else {
              originalName = StringUtils.split(name, ", ");
              record.setValue("name__v", originalName[1]);
          }
          // Save changes to the current record
          RecordService recordService = ServiceLocator.locate(RecordService.class);
          recordService.batchSaveRecords(VaultCollections.asList(record)).ignoreErrors().execute();
      }
   }
 
 
A class that implements the RecordAction interface must implement the following methods: The RecordActionInfo annotation has the following elements:

Document Actions

Documents can have custom actions that perform specific instructions. You can use a custom action to automate certain business processes. You can configure custom document actions as any of the following:

A Document Action is a Java class that implements the DocumentAction interface and has the DocumentActionInfo annotation.

The following is an example of a document user action. We query for a field on all binders a document is referenced in, and then set those values in a field on the document.

  @DocumentActionInfo(name = "get_partners__c", label="Find Partners", usages= Usage.USER_ACTION,lifecycle="general_lifecycle__c")
  public class FindPartners implements DocumentAction {
      public void execute(DocumentActionContext documentActionContext) {
      DocumentVersion docVersion = documentActionContext.getDocumentVersions().get(0);

      //Get the binders this document version is referenced in
      String QueryBindersDocIsIn = "SELECT parent_binder_id__sys " +
      "FROM binder_node__sys WHERE content_id__sys = " + docVersion.getValue("id", ValueType.STRING);
      QueryService queryService = ServiceLocator.locate(QueryService.class);
      QueryResponse bindersDocIsIn = queryService.query(QueryBindersDocIsIn);

      Iterator<QueryResult> iterator = bindersDocIsIn.streamResults().iterator();
      List<String> binderIds = VaultCollections.newList();
      while (iterator.hasNext()) {
         QueryResult idResults = (QueryResult) iterator.next();
          String parentBinderIds = idResults.getValue("parent_binder_id__sys", ValueType.STRING);
          binderIds.add(parentBinderIds);
      }
      //Get partner field values from the List of parent binders
      //Binder IDs must be in a comma separated String for In statement
      String QueryPartners = "SELECT partners__c " +
      "FROM documents WHERE id CONTAINS (" + String.join(",", binderIds) + ")";

      QueryResponse binderPartnerValues = queryService.query(QueryPartners);
      Iterator<QueryResult> partnerIterator = binderPartnerValues.streamResults().iterator();

      Set<String> partnerValues = VaultCollections.newSet();

      while (partnerIterator.hasNext()) {
          QueryResult partnerResults = (QueryResult) partnerIterator.next();
          partnerValues.addAll(partnerResults.getValue("partners__c", ValueType.REFERENCES));
      }

      List<String> partnerValueList = VaultCollections.newList();
      partnerValues.stream().forEach(partner -> partnerValueList.add(partner));

      DocumentService docService = ServiceLocator.locate((DocumentService.class));

      docVersion.setValue("partners__c", partnerValueList);
      docService.saveDocumentVersions(VaultCollections.asList(docVersion));
      }

  public boolean isExecutable(DocumentActionContext documentActionContext) {
      return true;
  }
 }
 
 
A class that implements the DocumentAction interface must implement the following methods: The DocumentActionInfo annotation has the following elements:
Skip navigation links

Copyright © Veeva Systems 2017–2018. All rights reserved.