Products | Versions |
---|---|
TIBCO EBX | All versions from 5.8.0. |
In this article, we will explain how to launch a workflow inside a user service, that will redirect to the initial selection (where the user service was launched from) at work item completion.
Before reading this article you should be aware of the UserService API.
Please see links in "reference" section.
You can use this method to launch a workflow:
We will use a workflow publication named "BasicWorkflow" and configured it to open the first task at launch in its model configuration:
The workflow will be launched in a a new navigation context in a separate sub-session, namely, a UIHTTPManagerComponent or Web Component.
Documentation: https://docs.tibco.com/pub/ebx/5.9.8/doc/html/Java_API/com/orchestranetworks/ui/UIHttpManagerComponent.html
There will be one header per session:
UIHTTPManager component declaration:
LaunchWorkflowService.java// Retrieve the ProcessLauncher and launch the workflow Repository repository = context.getRepository(); Session session = context.getSession(); WorkflowEngine engine = WorkflowEngine.getFromRepository(repository, session); ProcessLauncher launcher = engine.getProcessLauncher(PublishedProcessKey.forName( "BasicWorkflow" )); ProcessLauncherResult result = launcher.launchProcessWithResult(); WorkItemKey workItemKey = result.getWorkItemKey(); //Creation of the UIHTTPManagerComponent that will open the work item UIHttpManagerComponent managerComponent = writer.createWebComponentForSubSession(); managerComponent.selectWorkItem( true , workItemKey); managerComponent.setCloseButtonSpec(UIHttpManagerComponent.CloseButtonSpec.CROSS); |
In the user interface, that component will be inside an iframe HTML object.
// Iframe construction String iFrameURL = managerComponent.getURIWithParameters(); String iFrameId = "myIFrame" ; String jsFnListenerName = "syncIFrameToWorkspace" ; writer.add( "<iframe " ).addSafeAttribute( "id" ,iFrameId).addSafeAttribute( "src" , "" ).addSafeAttribute( "frameBorder" , "0" ).add( ">" ).add( "</iframe>" ); // Iframe dynamic "resize to workspace" function declaration writer.addJS( "function " ).addJS(jsFnListenerName).addJS( "(size) {" ); writer.addJS( " var iFrameEl = document.getElementById(\"" + iFrameId + "\");" ); writer.addJS( " iFrameEl.style.height = size.h + \"px\";" ); writer.addJS( " iFrameEl.style.width = size.w + \"px\";" ); writer.addJS( "}" ); writer.addJS_addResizeWorkspaceListener(jsFnListenerName); // Setting the iframe URL writer.addJS( "document.getElementById(\"" ).addJS(iFrameId).addJS( "\").src = \"" ).addJS(iFrameURL).addJS( "\";" ); |
Iframe documentation: https://docs.tibco.com/pub/ebx/5.9.8/doc/html/en/user_interface/coding_recommendations.html#UICustomDevRecommendations_HTML_iFrames
We will also implement another sub-session web component which will be used to redirect the web page to the parent session when the Accept or Reject button is pressed.
At the end of the workflow manager component, we want to redirect to the redirection manager component:
LaunchWorkflowService.javamanagerComponent.setRedirectionURI(redirectionComponent.getURIWithParameters()); |
Here is the implementation of the redirection manager component:
// Creation of the redirection UIHTTPManagerComponent UIHttpManagerComponent redirectionComponent = writer.createWebComponentForSubSession(); redirectionComponent.selectNode(repository.getReferenceBranch().findAdaptationOrNull(AdaptationName.forName( "TestNewLaunchWorkflow" )), Path.parse( "/root/table" )); //select a node where the redirection service is executable redirectionComponent.setService(ServiceKey.forName( "RedirectionService" )); |
This component will launch another user service, in which we will call a Javascript function of the parent HTML object.
That parent object will be the container of the sub-session, which is in the parent session.
Being in the parent session, we can then redirect the page to any URL.
We choose to redirect to the URL that corresponds to the initial selection.
Here is the implementation of the redirectionService JSP:
RedirectionService.javawriter.addJS( "ebx_getContainerWindow().parent.redirect();" ); //Call JS function of the parent // FOR VERSIONS BELOW 5.9.0, use this instead: //writer.addJS("parent.redirect();"); |
Javascript redirection function declaration:
writer.addJS( "function redirect() {window.location.href='" +sc.getURLForEndingService()+ "'}" ); |
User services documentation:
Knowledge base article: