0

Update document roles through Event Action using SDK

Is it possible to update document roles with Java SDK using:

a. event actions

b. State entry action

 

The only SDK actions (events or state entry action) which are available are (screenshot attached):

a. User Action

b. Entry Action

c. HTTP calls

d. field update

 

Please advise.

 

Thanks,
Deepak

 

1 comment

  • Avatar
    Kevin N

    Hi Deepak,

    The samples on the developer portal (https://developer.veevavault.com/sdk/#sample-code) are just some examples of what you can do with the SDK; they do not cover every functionality of the SDK.

    For a full read out of all functionality, you should refer to the Javadocs at https://repo.veevavault.com and then write additional code into your actions/triggers as you see fit.

    In your particular case, yes, you can update document roles using the DocumentRoleService and it's associated classes. This can be done via any SDK entry point. You can find the reference material and basic examples at: https://repo.veevavault.com/javadoc/vault-sdk-api/19.1.0/docs/api/com/veeva/vault/sdk/api/role/package-summary.html.


    For example:

    @DocumentActionInfo(label="SDK: Document Role Service Example")

    public class DocumentRoleServiceExample implements DocumentAction {

    public boolean isExecutable(DocumentActionContext documentActionContext){
    return true;
    }

    public void execute(DocumentActionContext documentActionContext) {

    LogService logService = ServiceLocator.locate((LogService.class));

    // Role to check on the Document
    String ROLE_TO_CHECK = "editor__v";

    DocumentRoleService docRoleService = ServiceLocator.locate(DocumentRoleService.class);

    // Assuming this is a Document use action, there is one document in the documentActionContext
    List<DocumentVersion> docVersionList = documentActionContext.getDocumentVersions();
    DocumentVersion docVersion = docVersionList.get(0);

    // Get current user UID
    String currentUserId = RequestContext.get().getCurrentUserId();

    // Get document Role
    GetDocumentRolesResponse docRolesResponse = docRoleService.getDocumentRoles(docVersionList, ROLE_TO_CHECK);
    DocumentRole checkedRole = docRolesResponse.getDocumentRole(docVersion);


    // Check if current user is in role
    boolean isUserInCheckedRole = docRoleService
    .getUserInDocumentRoles(currentUserId, VaultCollections.asList(checkedRole))
    .isUserInDocumentRole(checkedRole);

    // Add current user to role
    if (!isUserInCheckedRole) {
    DocumentRoleUpdate docRoleUpdate = docRoleService.newDocumentRoleUpdate(ROLE_TO_CHECK, docVersion);
    docRoleUpdate.addUsers(VaultCollections.asList(currentUserId));

    //Add up to 500 role updates in a single batch
    docRoleService.batchUpdateDocumentRoles(VaultCollections.asList(docRoleUpdate))
    .rollbackOnErrors()
    .execute();

    }
    }
    }

     

    Regards,

    Kevin

Please sign in to leave a comment.