See: Description
Interface | Description |
---|---|
DeleteDocumentVersionsResponse |
Response from a call to
DocumentService.deleteDocumentVersions(List) (List)}. |
DocumentAttachment |
Represents the target attachment.
|
DocumentAttachmentFileReference |
Represents an attachment file from the current or from another vault.
|
DocumentFileReference |
Represents a document file from the current or from another vault.
|
DocumentRendition |
Represents the target document-version rendition.
|
DocumentRenditionFileReference |
Represents a document-version rendition file from the current or from another vault.
|
DocumentService |
Provides methods to update and delete documents.
|
DocumentSourceFileReference |
Represents a document-version source file from the current or from another vault.
|
DocumentVersion |
Represents a document version.
|
PositionalDocumentVersionId |
Represents a successful result of processing a document in a batch operation, such as a save or delete.
|
SaveDocumentVersionsResponse |
Response from a call to
DocumentService.saveDocumentVersions(List) . |
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);
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("Claims"));
newVersion.setValue("subtype__v", VaultCollections.asList("Core Message Map"));
newVersion.setValue("lifecycle__v", VaultCollections.asList("Claims"));
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, "1_0_1", "viewable_rendition__v");
DocumentRendition rendition = documentService.newDocumentRendition(documentRenditionFileReference, "1_0_1", "viewable_rendition__v");
documentService.createRenditions(VaultCollections.asList(rendition));
}
}
Copyright © Veeva Systems 2017–2021. All rights reserved.