0

Veeva JDK- DocumentAction - Use Case

Today at 12:12 Mithun Kumar Soni

Hi Team,

We want to implement one Use Case - If a user creates one document and when he/she initiate the workflow, the document owner should get updated with another user based on role.

In the initial phase, We are trying to retrieve the document version, but when I tested after connecting with Vault, It is not working.
I have other queries -

What is use of name and Label ?
How can we enforce the State level condition?

Please help me understanding the clarifying these issues.

PFB The code:

@DocumentActionInfo(name = "LifecycleUserAction", label="Send for TEST",lifecycle="lifecyclename__vs", usages =Usage.USER_ACTION)
public class DocService implements DocumentService, DocumentAction, DocumentRole{

@Override
public void execute(DocumentActionContext contxt) {

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


DocumentVersion docVersion = contxt.getDocumentVersions().get(0);


System.out.println(docVersion);
String id = docVersion.getValue("id", ValueType.STRING) + "_" +
docVersion.getValue("major_version_number__v", ValueType.NUMBER).toString() + "_" +
docVersion.getValue("minor_version_number__v", ValueType.NUMBER).toString();

System.out.println(id);
}

}

Please note – I have already implemented the other methods.

In the above code, I am trying to print the document version.

Thanks in advance for your help.

7 comments

  • Avatar
    Kevin N

    Hi Mithun,

    Have you had a chance to review our samples? We have sample code that shows basic use cases for documents and objects.

    The samples are at https://developer.veevavault.com/sdk/#sample-code.

    Your posted code has some issues such as trying to implement the DocumentService and DocumentRole which you should not be trying to implement.

     

    As for you questions:

    What is use of name and Label ? 

    • The name is deprecated and is no longer necessary.
    • The label is the label of the action as seen in the UI. This label is displayed once the code is deployed.

    How can we enforce the State level condition?

    • Can you clarify on what you are trying to accomplish?
    • Normally through the UI, you can define conditions for when an entry action is performed during a state change 
    • With the SDK, you can potentially either create an entry SDK action that checks for certain conditions when entering a particular state. This entry action can then be coded to either fail the state action or allow the state change to occur based on some conditions. If you want it to fail, you would throw a RollbackException.
    • In the SDK, you can also grab the status__v value from a QueryService VQL query (e.g. select status__v from documents where id = <id>) and do decide to some logic based on the status.

     

    Thanks,
    Kevin

  • Avatar
    Mithun Kumar Soni

    Hi Kevin,

     

    Thanks for your responce.

     

    RE: Your posted code has some issues such as trying to implement the DocumentService and DocumentRole which you should not be trying to implement. - I have removed it.

    My UseCase -

    There are two roles, Originator and Approver. Originator creates a document (Current status is Draft) and routed for approval to Approver. After routing the document, document status changes to In Review. Now, during this state transition (from 'Draft' to 'In Review'), We want to transfer the ownership (owner role) of this document from Originator to Approver.

     

    In the below code, I am trying to verfy if my code can print the document version. But When I connect it with Vault and roughted for approval, code is not printing the document version.

     

    @DocumentActionInfo(name = "LifecycleUserAction", label="Send for TEST",lifecycle="lifecyclename__vs", usages =Usage.USER_ACTION)
    public class DocService implements DocumentAction{

    @Override
    public void execute(DocumentActionContext contxt) {

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


    DocumentVersion docVersion = contxt.getDocumentVersions().get(0);


    System.out.println(docVersion);
    String id = docVersion.getValue("id", ValueType.STRING) + "_" +
    docVersion.getValue("major_version_number__v", ValueType.NUMBER).toString() + "_" +
    docVersion.getValue("minor_version_number__v", ValueType.NUMBER).toString();

    System.out.println(id);
    }

    }

      

    Could you please help me on this?

     

    Thanks,

    Mithun

     

     

     

  • Avatar
    Kevin N

    Hi Mithun,

    Have you review the documentation on Document Actions (https://developer.veevavault.com/sdk/#actions)?

    There are multiple pieces that need to be in place for Document Actions to function and go through debug:

    1. Create the SDK Document Action code. 
    2. Deploy the Document Action code into vault (https://developer.veevavault.com/sdk/#deploying-code)
    3. The USAGE annotation on the code should be equal to Usage.LIFECYCLE_ENTRY_ACTION or Usage.UNSPECIFIED if you want to hit the code when a document is changed into a lifecycle state (https://repo.veevavault.com/javadoc/vault-sdk-api/18.3.0/docs/api/com/veeva/vault/sdk/api/action/Usage.html) 
    4. Once deployed, configure a document lifecycle user action or entry action to use the SDK Document Action code.
    5. You can now debug the SDK Document Action.
    6. initiate the lifecycle state change or activate the SDK user action.

    Please note that code with System.out.println cannot be deployed. You should be using the LogService to print info to the console. For example:

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

    logService.info("This is a comment.");

     

    Thanks,
    Kevin

  • Avatar
    Mithun Kumar Soni

    Hi Kevin,

    Thanks for your help again.

    I followed the steps that you have mentioned in the last post. But after initiating the workflow, it does not print the log. Here, My intention is to verify if my custom code is working fine. Once it get confirmed, I will move ahead with other Use Case.

    I have attached screenshots of my IDE code along with the vault Document Action deployed code.

    Here, I am printing the logs. But it is not working

    Please let me where is the gap?

    Thanks,

    Mithun

     

     

     

     

  • Avatar
    Kevin N

    Hi Mithun,

    I took a look in your vault. You have a step to complete still:

    • Step 4: Once deployed, configure a document lifecycle user action or entry action to use the SDK Document Action code

    Here you have to perform the following (http://vaulthelp.vod309.com/wordpress/admin-user-help/document-lifecycles-admin/defining-doc-state-entry-actions/):

    1. Navigate to that document lifecycle "Reference Document",
    2. Select the state you want to put an entry action on - "In Review"
    3. Select the "Entry Action" tab,
    4. and then finally create an entry action that points to your "Move to In-Review" SDK document action

     

    Once configured, you can then attach the debugger, move a document into "In Review", and then you'll see the message in the debugger console. Or, you can enable the Debug Log for your user and the LogService messages will be displayed there.

     

    Thanks,

    Kevin

  • Avatar
    Mithun Kumar Soni

    Hi Kevin,

    I have changed the Usages to USER_ACTION. And User Action is already configured in Draft State. I want, when we send the document to – In Review State, below code should print the current document Id in the log. But after making these changes, still the program does not works.

    Please have a look in below screenshots -

     

     

    User Action is already configured.

     

     

    Please let me know why this is not working. My use case is - when I send the document from Draft to Next state (In Review), it should print the document version is in the log as mentioned in the code.

     

    Thanks,

    Mithun

  • Avatar
    Kevin N

    This post was moved to a Zendesk support ticket and resolved there. I've marked this post as closed.

Post is closed for comments.