0

Veeva Java SDK- Error During Document Role Update

Hi Team,

 

I am trying to update the Document role with another user existing in the document with different role.

I am getting following error, could please help me why I am getting this error:

This operation could not complete successfully. You may need to contact your vault’s administrator about this error caused by: [Encountered [1] error(s) in batch.] Error Id: [bff65345-cf7a-4fa3-83af-786c2092e848]

Thanks,

Mithun

 

4 comments

  • Avatar
    Jean Christophe Meriaux

    Hi Mithun,

    See below what I can think about in terms of what can go wrong when assigning roles using the role service..

    Also I would try to log the exception in the Debug Log to get more details on the exception itself. I provide more details on how to do this below. But Go to Logs > Debug Logs and create a debut log first...

    Let me know if it helps,

    Thanks - Jean-Christophe ( Vault platform product management),

    +++++++++++++++++++++++++++++

    When updating a user role on a document, certain exceptions can happen, so I would look in this direction first,

    1) role API name is not referencing a role configured on the document lifecycle 

    If you check under Configuration > Document Lifecycle > Lifecycle > Role, you should see the role name for instance editor__vs

    2) certain roles support only one user (owner, coordinator)

     

    Also when you invoke the batchUpdateDocumentRoles interface, you can specify a transaction strategy on the returned BatchOperation object (rollbackOnErrors, IgnoreErrors, onErrors..), 

    For example, this will call a consumer function logging the error in the logService if there are exceptions,

    batchUpdateDocumentRoles( ....).onErrors(listConsumerError).execute();

    But first you'll need to locate the log Service 

    // Locate services
    LogService logService = ServiceLocator.locate(LogService.class);

    And before calling the batchUpdateDocumentRoles you can define this function that will be called back when errors are happening,

    // Consumer Function trapping errors
    Consumer<List<BatchOperationError>> listConsumerError = (theList) -> theList.stream()
    .forEach(error -> {

    String errmsg = error.getInputPosition() +
    error.getError().getType() +
    error.getError().getSubtype() +
    error.getError().getMessage();

    logService.error(errmsg);
    });

     

     

     

  • Avatar
    Mithun Kumar Soni

    Hi Jean,

    Here the role is Document Owner. As said - Owner role support only a single user. Is there any way to update the owner role. Use Case - if one user create one document. after createting , when he sent it for approval, the document owner should get updated with another user of the document. It that possible?

     

     

     

  • Avatar
    Kevin N

    Hi Mithun,

    This is a reminder that you'll need to make use of the Debug Logs (https://developer.veevavault.com/sdk/#debug-log) and the debugger to properly troubleshoot while developing code. The logs will provide details on all errors.

    In this case, the Debug Logs would return a full error message similar to below:

    2019-01-23 17:06:51,330 Documentaction.com.veeva.vault.custom.actions.DocumentRoleServiceExample ERROR ErrorId [375d49dc-adc4-4c17-9abb-4db18e1401aa] java.lang.Throwable: Vault Java SDK Error: [Encountered [1] error(s) in batch.] Error Id: [375d49dc-adc4-4c17-9abb-4db18e1401aa]
    at ...(Unknown Source)
    Caused by: java.lang.Throwable: [Input Position [0] Error [{type='INVALID_DATA', subtype='null', message='Role [owner__v] does not allow multiple users'}]]
    ... 1 more


    To resolve this and add a different owner, you need to remove the current owner at the same time as adding the new owner. For example:

    DocumentRoleUpdate docRoleUpdate = docRoleService.newDocumentRoleUpdate("owner__v", docVersion);
    docRoleUpdate.addUsers(VaultCollections.asList(newOwnerUserId));
    docRoleUpdate.removeUsers(VaultCollections.asList(currentOwnerUserId));
    docRoleService.batchUpdateDocumentRoles(VaultCollections.asList(docRoleUpdate))
    .onErrors(batchOperationErrors -> {
    //Iterate over the caught errors.
    //The BatchOperation.onErrors() returns a list of BatchOperationErrors.
    //The list can then be traversed to retrieve a single BatchOperationError and
    //then extract an **ErrorResult** with BatchOperationError.getError().
    batchOperationErrors.stream().findFirst().ifPresent(error -> {
    String errMsg = error.getError().getMessage();
    int errPosition = error.getInputPosition();
    throw new RollbackException("OPERATION_NOT_ALLOWED", "Unable to add users to role because of '" + errMsg + "'.");
    });
    })
    .execute();


    Thanks,
    Kevin 

  • Avatar
    Mithun Kumar Soni

    Hi Kevin and Jean,

    Thanks for your support. Finally I achieved the use case.

    Thanks Again!!!

    Regards,

    Mithun

     

     

Please sign in to leave a comment.