3 Replies Latest reply: Aug 30, 2013 6:04 AM by Juw RSS

    Close a task programmatically

    Juw
      hi guys,
      need your help here :)
      i have a human task flow UI based from ADF.
      buy clicking a button my page will be redirected to a servlet that generate a pdf report using jasper.
      how can i close the task UI before get redirect to the servlet page ?

      or how can i get the current task id from my managed bean ? so the idea of the 2nd question is to update the outcome of the task using ITaskService .

      thanks before.
        • 1. Re: Close a task programmatically
          Juw

          is there anybody can help ?

          • 2. Re: Close a task programmatically
            Ravi Jegga

            Hi Juw

            On Button click, in managed bean you will have an Action method and in that try these 3 lines. It should close the currently opened taskDetails page.

            {code}

            import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;

            import org.apache.myfaces.trinidad.util.Service;

             

            FacesContext facesContext = FacesContext.getCurrentInstance();

            ExtendedRenderKitService service = Service.getRenderKitService(facesContext, ExtendedRenderKitService.class);

            service.addScript(facesContext, "window.opener = self;window.close();");

            {code}

            ***

            How to get taskId and pretty much anthing related to Task using APIs:

             

            Using official Public APIs:

            http://docs.oracle.com/cd/E14571_01/apirefs.1111/e10660/oracle/bpel/services/workflow/query/ITaskQueryService.html

            The first section in the above link, will have sample code to get all Task Details including taskId.

             

            NON Public APIs. In Jdeveloper you can get methods in this class like using go to defintion. Or use any simple Java Decompiler to decompile this .class file. It has pretty decent methods. Please NOTE since this is NOT public exposed API, the methods may change with newer versions. So just be alert when you use these non public apis.

            This class can be found in the JAR: ..../Oracle/Middleware115/Oracle_SOA1/soa/modules/oracle.soa.workflow_11.1.1/bpm-workflow-datacontrol.jar

             

            import oracle.bpel.services.workflow.worklist.adf.ADFWorklistBeanUtil

             

            ADFWorklistBeanUtil.getWorklistTaskId()

             

            *** Also how to get Logged in userid in managedbean ***

             

            1. BPM Workspace application is little tricky. When we login, we login into bpmWorkspace web application which has nothing to do with your actual taskforms web application.

            2. We deploy taskforms and based on roles and permissions, we get to see any tasks in the inbox. clicking on task, opens taskDetails page and this taskDetails page is specific to our Application.

            3. Getting logged in userid in this custom taskDetails or managed bean is not straight forward. There are few ways to try but it did NOT worked for me. Like adding an extra jar and settings in web.xml file etc.

            4. Below code snippet always and consistenly worked for me in managed bean. If anyone have simpler ways, please feel free to share it.

             

            {code}

                public String getLoggedInUser() {

                    String loggedInUser = null;

                    try {

                        String lookupClient = TaskFlowPropsUtil.getLookupClientType();

                        //logger.debug("lookupClient: " + lookupClient);

                        if (lookupClient != null) {

                            IWorkflowServiceClient wfSvcClient = TaskFlowPropsUtil.getWorkflowServiceClient(lookupClient);

                            //logger.debug("wfSvcClient: " + wfSvcClient);

                            if (wfSvcClient != null) {

                                ITaskQueryService queryService = wfSvcClient.getTaskQueryService();

                                //logger.debug("queryService: " + queryService);

                                if (queryService != null) {

                                    String contextStr = ADFWorklistBeanUtil.getWorklistContextId();

                                    IWorkflowContext aContext = queryService.getWorkflowContext(contextStr);

                                    //logger.debug("aContext: " + aContext);

                                    if (aContext != null) {

                                        loggedInUser = aContext.getUser();

                                    }

                                }

                            }              

                        }

                    } catch (Exception anException) {

                        logger.error("getLoggedInUser() -> Error: " + anException.getMessage(), anException);

                    }

                    //logger.debug("getLoggedInUser() -> LoggedInUser: " + loggedInUser);

                    return loggedInUser;

                }

            {code}

             

            Thanks

            Ravi Jegga

            • 3. Re: Close a task programmatically
              Juw

              {code}

              import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;

              import org.apache.myfaces.trinidad.util.Service;

               

              FacesContext facesContext = FacesContext.getCurrentInstance();

              ExtendedRenderKitService service = Service.getRenderKitService(facesContext, ExtendedRenderKitService.class);

              service.addScript(facesContext, "window.opener = self;window.close();");

              {code}

               

              with this code, not working in every UI, if you are still in a frame it didn't work, before post this question, i've already found this code in this same forum.

              i don't know what's wrong but its looks like the javascript is error.

              thanks