Skip navigation links

Package com.veeva.vault.sdk.api.document

This package provides interfaces to manage documents and binders.

See: Description

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

This package provides interfaces to manage documents and binders. The interfaces in this package allow you to:

Updating and Deleting Documents

Use DocumentService to create a DocumentVersion object, which is an instance of an existing document. You can then update field values or delete the document.

After updating or deleting a DocumentVersion, you need to execute a batch operation to commit the operation. For example, after updating a document, you need to execute DocumentService.saveDocumentVersions(java.util.List) (java.util.List)} to save your changes.

In the following example, we update fields on the existing document ID 320, delete document ID 310, and delete a specific version of document ID 330.

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

 DocumentVersion documentVersion = documentService.newDocumentWithId("320");
 LocalDateTime ldt = LocalDateTime.of(2016, Month.AUGUST, 22, 14, 30);
 documentVersion.setValue("expiration_date__vs", LocalDate.now());
 List languageList = VaultCollections.newList();
 languageList.add("en_US");
 documentVersion.setValue("language__v", languageList);
 documentVersion.setValue("approved__c", Boolean.FALSE);
 documentVersion.setValue("datetime__c", ldt.atZone(ZoneId.of("Asia/Kuala_Lumpur")));

 DocumentVersion documentVersion2 = documentService.newDocumentWithId("310");
 DocumentVersion documentVersion3 = documentService.newDocumentVersion("330_0_1");

 List versionsToUpdate = VaultCollections.newList();
 versionsToUpdate.add(documentVersion);
 List versionsToDelete = VaultCollections.newList();
 versionsToDelete.add(documentVersion2);
 versionsToDelete.add(documentVersion3);

 documentService.deleteDocumentVersions(versionsToDelete);
 documentService.saveDocumentVersions(versionsToUpdate);
 
 

Creating Documents, Renditions, and Versions

The following example uses ConnectionService, DocumentService, and FileReference to set set the source file, get new version information, and create a new attachment and rendition.
 
 @DocumentActionInfo(label = "testCode")
 public class DeepCopyDocument implements DocumentAction {
     @Override
     public boolean isExecutable(DocumentActionContext documentActionContext) { return true; }

     @Override
     public void execute(DocumentActionContext documentActionContext) {

         ConnectionService connectionService = ServiceLocator.locate(ConnectionService.class);
         ConnectionContext connectionContext = connectionService.newConnectionContext("connectionApiName", ConnectionUser.CONNECTION_AUTHORIZED_USER);

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

         DocumentSourceFileReference documentSourceFileReference  = documentService.newDocumentSourceFileReference(connectionContext, "1_0_1");
         DocumentVersion documentVersion = documentService.newDocument();
         documentVersion.setValue("type__v", VaultCollections.asList("Claims"));
         documentVersion.setValue("subtype__v", VaultCollections.asList("Core Message Map"));
         documentVersion.setValue("lifecycle__v", VaultCollections.asList("Claims"));
         documentVersion.setValue("name__v", "file name");
         documentVersion.setSourceFile(documentSourceFileReference);
         documentVersion.suppressRendition();

         SaveDocumentVersionsResponse response = documentService.createDocuments(VaultCollections.asList(documentVersion));

         String newDocVersionId = response.getSuccesses().get(0).getDocumentVersionId();

         //Get new version info
         String[] parts = StringUtils.split(newDocVersionId, "_");
         String docId = parts[0];
         Integer major = Integer.valueOf(parts[1]);
         Integer newMinor = Integer.valueOf(parts[2]) + 1;

         DocumentSourceFileReference secondVersionSourceFileReference  = documentService.newDocumentSourceFileReference(connectionContext, "1_0_2");
         DocumentVersion newVersion = documentService.newVersion(docId);
         newVersion.setValue("type__v", VaultCollections.asList("Claim"));
         newVersion.setValue("lifecycle__v", VaultCollections.asList("Claim"));
         newVersion.setValue("status__v", VaultCollections.asList("Draft"));
         newVersion.setValue("name__v", "1-17-2 v2");
         newVersion.setValue("major_version_number__v", BigDecimal.valueOf(major));
         newVersion.setValue("minor_version_number__v", BigDecimal.valueOf(newMinor));
         newVersion.setSourceFile(secondVersionSourceFileReference);

         documentService.migrateDocumentVersions(VaultCollections.asList(newVersion));

         //create attachment
         DocumentAttachmentFileReference documentAttachmentFileReference = documentService.newDocumentAttachmentFileReference(connectionContext, "1");
         DocumentAttachment documentAttachment = documentService.newDocumentAttachment(documentAttachmentFileReference, docId);
         documentService.createAttachments(VaultCollections.asList(documentAttachment));

         //create rendition
         DocumentRenditionFileReference documentRenditionFileReference = documentService.newDocumentRenditionFileReference(connectionContext, "viewable_rendition__v", "1_0_1");
         DocumentRendition rendition = documentService.newDocumentRendition(documentRenditionFileReference, "1_0_1", "viewable_rendition__v");
         documentService.createRenditions(VaultCollections.asList(rendition));
     }
 }
 
 
Skip navigation links

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