Launch a workflow from a UserServiceExtended

Launch a workflow from a UserServiceExtended

book

Article ID: KB0073984

calendar_today

Updated On:

Products Versions
TIBCO EBX All versions from 5.8.0.

Description

Before reading this article you should be aware of the UserService API, and especially about service declaration.

Please see links in "reference" section.

    In this article we will explain how to launch a workflow from a user service without display, namely a UserServiceExtended.
    You can use this method to launch a workflow:

    • Directly in the EBX user interface, from a Services or Actions menu
    • From a perspective or a toolbar as soon as it is set available in the declareWebComponent method of the service declaration

    We will use a workflow publication named "BasicWorkflow" and configured it to automatically open the first step in its model configuration:

    User-added image

    Issue/Introduction

    Launch a workflow from a UserServiceExtended

    Resolution

    UserServiceExtended

    Compared to a UserService, the UserServiceExtended has one more method, initialize, that is called on service creation, and allows to perform without-display operations before display.

    Restrictions:

    • Currently user services without display of nature Association or AssociationRecord are not supported and should not implement this interface.
    • Services without display are also not supported if called from a perspective action or as a Web component.

    The context of the initialize method allows us to retrieve the entity selection, and pass it as as a data context variable when launching the workflow. 

    In our example, everything will be done without display, from the worfklow engine retrieval to the redirection to the first work item, so we only need to implement the initialize() method.

    At the end of the workflow, the user will be redirected to the inbox view.

    If you want to act on the redirection, you will have to implement a more complex solution with the UserService API.

    Please see article: Launch a workflow inside a UserService and redirect to the initial selection.
     

    Example of initialize method implementation

    public UserServiceEventOutcome initialize(UserServiceInitializeContext<RecordEntitySelection> aContext) {
             
            try {
            Repository repository = aContext.getRepository();
            Session session = aContext.getSession();
             
            // Retrieve the process launcher of the "BasicWorkflow" workflow
             
            WorkflowEngine engine = WorkflowEngine.getFromRepository(repository,session);
            ProcessLauncher launcher = engine.getProcessLauncher(PublishedProcessKey.forName("BasicWorkflow"));
             
            // Retrieve the selected record and set its ID as a data context variable
             
            Adaptation selectedRecord = aContext.getEntitySelection().getRecord();
            String selectedRecordID = selectedRecord.getString(Path.parse("./id"));
            launcher.setInputParameter("selectedRecord", selectedRecordID);
             
            // Launch the workflow instance and get the work item key
             
            ProcessLauncherResult result = launcher.launchProcessWithResult();
            WorkItemKey workItemKey = result.getWorkItemKey();
             
            // At the end, close the service and redirect to the next work item
            return UserServiceNext.nextWorkItem(workItemKey, true);
     
            }
            catch (OperationException e) {
                return null;
     
            }
     
    }

    Additional Information

    User services documentation:

    Knowledge base article:

    UserServiceExtended java documentation: https://docs.tibco.com/pub/ebx/5.9.7/doc/html/en/Java_API/com/orchestranetworks/userservice/UserServiceExtended.html

    Attachments

    Launch a workflow from a UserServiceExtended get_app
    Launch a workflow from a UserServiceExtended get_app