Update a field value of a document (ALLVERSIONS) using SDK

Hi, I have a use case where I need to update a specific field value of ALLVERSIONS document (0.1, 0.2, 1.0 etc) when a document enters steady state using SDK.

documentActionContext.getDocumentVersions() gives me only the document version that this action is invoked on, I'm looking to see if there is any other method that would give me the entire version tree list so that I can iterate through and update field value on all versions. Or Query is the only way that I can get ALLVERSIONS document to parse through?

I'm looking for a sample code to achieve this. Any help is appreciated.



  • Avatar
    Adam McMillan

    Thank you for this feedback. There is no method today that returns all document versions, but I will discuss it with the team for future roadmap consideration

  • Avatar
    Durvasan, Ravi Shankar

    Hi Adam, Thanks for your response. Appreciate it.

    I'm trying to achieve this use case using QueryService.

    But doesn't look like SDK is capable of updating non-latest version docuements.

    Can you please confirm?

    Here is my logical SDK code flow:

    - String document_id = docVersion.getValue("id", ValueType.STRING);

    - QueryService queryService = ServiceLocator.locate(QueryService.class);

    - String queryString = "SELECT id, status__v, minor_version_number__v, major_version_number__v, <filed_to_update> FROM ALLVERSIONS documents where id = '" + document_id +"'";

    - QueryResponse queryResponse = queryService.query(queryString);

    - List<DocumentVersion> docVersionList = VaultCollections.newList();

    - Iterator<QueryResult> queryResults = queryResponse.streamResults().iterator();

    while(queryResults.hasNext()) {
    QueryResult queryResult = queryResults.next();
    String version_id = queryResult.getValue("id", ValueType.STRING) + "_" +
    queryResult.getValue("major_version_number__v", ValueType.NUMBER).toString() + "_" +
    queryResult.getValue("minor_version_number__v", ValueType.NUMBER).toString();

    DocumentVersion docVersionQuery = docService.newDocumentVersion(version_id);

    docVersionQuery.setValue("<field to update>", "updated value");



    I'm getting the below error while executing the above SDK code as user entry actions on one of the life cycle states.

    errorType[OPERATION_NOT_ALLOWED] errorMessage[Vault Java SDK Error: [Encountered [1] error(s) in batch.] Error Id: [7fb40bc2-2c64-4690-95cb-f7a0e73cf700]]

    Can you please confirm if SDK is capable of updating bothe LATEST and non-latest versions of documents?

    Appreciate your help.



  • Avatar
    Adam McMillan

    Yes you're right, the SDK documentService can only update the fields on the latest version of the document, unless you use HTTP callout and use our document APIs to update prior versions:


  • Avatar
    Durvasan, Ravi Shankar

    Thanks for confirming Adam.

    Looking at the developer guide, the actual intended use of HTTP callout is to integrate multiple vaults. is it recommended to use HTTP callout to update previous version documents within the same vault?

    Thanks again



  • Avatar
    Adam McMillan

    Since it is a single document API (not bulk), I'd hesitate to call it necessarily recommended practice, for performance reasons. I don't believe there's a reason you couldn't though. This HTTP callout method is helpful for invoking API abilities that have not yet made it into the SDK

  • Avatar
    Durvasan, Ravi Shankar

    Thanks for your comments Adam. Yes I ended up using API call from SDK. Thanks

Please sign in to leave a comment.