Hi,

We all know that there is no standard solution provided by SAP to log out an idle user.After a number of futile search attempts in google/SDN for a solution, I set about to find a solution on my own. Find below the steps to create the simple portal component which tracks the user inactivity.


I have already  seen couple of solutions for this but they have minor issues and did not suit my requirements.


1. Portal user idle timeout using dialog windows – Client side solution => this solution does not seem to work for AJAX Framework in recent releases and did not track the user clicks, mouse movement etc. It worked only for Navigation event in portal. Basically, it will consider the user idle if he does not navigate. The user will be timed out

2. http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/309379b6-bb9b-2d10-feb1-91f2a7078574?overridelayout=true => Though this one says that it can track the user clicks, mouse movements etc, the logoff functionality did not work in NW portal 7.4.


My requirement is to track the user events in the content area as well before deciding if the user is idle or not.


The portal component which I have developed is very basic and uses Jquery. It tracks Key press, mouse movements in content area of the portal framework.


1. Go to Development Infrastructure perspective and create a EP DC


Screen Shot 2015-07-27 at 15.48.20.png

Screen Shot 2015-07-27 at 15.50.40.png

Click finish.

2. Create a ‘Portal Application Object’ in this EP DC.

Screen Shot 2015-07-27 at 15.52.33.png

Click Next. Select the DC created in step 1

Screen Shot 2015-07-27 at 15.52.41.png

Click Next. Choose Portal Component -> JSPDynPage

Screen Shot 2015-07-27 at 15.52.58.png

Click Next.  Enter the JSP class, package and file name.

Screen Shot 2015-07-27 at 15.53.19.png

Click Finish.

3. Open the TimeOut.jsp file under dist/PORTAL-INF/pagelet folder and copy the code below. Make sure that you place the relevant Jquery file under /scripts folder.

<html>

<head>

<% String mimeUrl = componentRequest.getWebResourcePath(); %>

  <script type=“text/javascript” src=<%=mimeUrl%>/scripts/jquery-1.11.2.min.js”></script>

<script type=“text/javascript”>

var idleTime = 0;

$(document).ready(function () {

    //Increment the idle time counter every minute.

    idleInterval = setInterval(timerIncrement, 120000); // 2 minute

    //Zero the idle timer on mouse movement.

    $(‘body’).mousemove(function (e) {

     idleTime = 0;

     document.querySelector(‘.content .value’).innerHTML = idleTime + “mouse moved”;

    });

    $(‘body’).keypress(function (e) {

        idleTime = 0;

        document.querySelector(‘.content .value’).innerHTML =idleTime +  “key press”;

    });

    $(‘body’).click(function() {

       idleTime = 0;

       document.querySelector(‘.content .value’).innerHTML = idleTime + “mouse moved”;

    });

});

function timerIncrement() {

    idleTime = idleTime + 1;

    document.querySelector(‘.content .value’).innerHTML = idleTime;

    if (idleTime > 0) {

        if (confirm(‘Your session is inactive for the last 2 minutes. Press OK to log off. Press cancel to extend the session.’) == true) {

          window.location.assign(“/irj/servlet/prt/portal/prtroot/com.sap.portal.navigation.masthead.LogOutComponent?logout_submit=true”);

      

        } else {

        idleTime = 0;

        document.querySelector(‘.content .value’).innerHTML = idleTime

        }

  

     

    }

}

</script>

</head>

<body>

<div class=“content”>Status:  <span class=‘value’></span></div>

</body>

</html>

4. Build and Deploy the DC to the server.

5. Create an iview for the deployed application. You can preview and test before embedding it in the portal framework.

  Preview the iview and do not do any action on it. You can see the pop up below after 2 minutes.

Screen Shot 2015-07-27 at 16.04.47.png

6. Now you can place this iview in the framework page under ‘Technical Hidden iviews Container’.

Screen Shot 2015-07-27 at 16.04.27.png

7. Save the Framework page. Log off and login to the portal.

As you can see, code is simple and timings and messages can be customised as per your requirements.

I have placed the following HTML element in the code so as to check if the mouse movements and user clicks are tracked or not.

<div class=“content”>Status:  <span class=‘value’></span></div>

Since you have placed the iview under hidden iviews, you will not be able to see this HTML element. If you want to debug , please move the iview to one of the other containers and make the component visible on the screen.

Feel free to comment any improvisations on this approach.

To report this post you need to login first.

38 Comments

You must be Logged on to comment or reply to a post.

      1. Massimo Guarino

        Thanks Sharadha,

        Now working fine, great work!!

        I want to apply this solution to Fiori Framework page, but if I add the iview to Fiori Framework page, nothing is displayed anymore.

        Immagine3.png

        Immagine2.png

        Do you have any suggestion for me?

        Thanks in advance

        Massimo

        (0) 
            1. Sharadha K Post author

              Massimo,

              can you change the browser language to english and send the log. I do not understand the error.

              Also to change the confirm pop up to alert, change the lines below.

              if (confirm(‘Your session is inactive for the last 2 minutes. Press OK to log off. Press cancel to extend the session.’) == true) {

                        window.location.assign(“/irj/servlet/prt/portal/prtroot/com.sap.portal.navigation.masthead.LogOutComponent?logout_submit=true”);


              to


              alert(‘<message>’)



              Sharadha

              (0) 
              1. Massimo Guarino

                Thank you Sharadha,

                I have changed my code and I’ve added the Timeout iview directly in the page where I need to have a TimeOut, and now it’s working fine.

                The problem is still when I add the Timeout iview in the Fiori Framework Page.

                The fiori launchpad is displayed blank,  but the time out works fine

                this is the console result, no errors are displayed:

                Immagine11.png

                Thank again,

                very good work!!

                Massimo

                (0) 
  1. meghal shah

    Hi  Sharadha,

    As mentioned above i have added .js file in my project still i am getting below mentioned error.

    Please suggest.

    Consol.PNG

    Project.PNG

    Thanks & Regards,

    Meghal Shah

    (0) 
  2. Venkat K

    Hi Sharadha,


    I have the same  idle requirement in Portal,i have followed  same your document has given  above. i have  added the Jquery file to the project under /scripts folder


    http://code.jquery.com/jquery-1.11.2.min.j


    whenever deploying i am  getting some  below deployment error,please kindly Help me, this is very high priority


    Thanks in Advance


    Venkat

    NWDS1.PNG

    (0) 
      1. Venkat K

        Hi Meghal Shah,


        Port Side no problem,port was already opened, its fine but i am getting that error.


        Please help me


        Thanks

        Venkat

        (0) 
        1. Venkat K

          Hiii All,

          Is there any process to deploy direct to server,if anyone knows please tell me how clearly

          I really appreciate any help.



          Thanks

          Venkat.

          (0) 
        2. meghal shah

          Hi Venkat ,

          1. Make a Login with sidadm on NW7.3 WebAs server.

          2. Navigate to  /usr/sap/SID/Instance<No>/j2ee/deployment/scripts

          3. locate deploy.csh (used in Unix environment) \ deploy.bat (Used on windows platform) file under scripts directory.

          4.  Execute following command to deploy .ear \ .war \ .sda files server

          ./deploy.csh  username:password@FQDN Name of server:50004 /location of file

          Thanks & Regards,

          Meghal Shah

          (0) 
          1. Venkat K

            Hi Meghal Shah,

            I deployed .ear file using Telnet  tool Successfully,then where i can find that .ear file application in Portal side,after finding application what process i need to follow kindly explain step by step.

            Thanks in advance Meghal

            Thanks

            Venkat

            (0) 
            1. Venkat K

              Dear Meghal Shah,

              Actually i am new to NWDS 7.3 so i  am unable to develop this Portal idle Time out Application,please provide any scratch document step by step,its very urgent for my Client in Production,if you provide document very helpful to me,please do needful.

              my mail id         venkat26.kv@gmail.com

              thanks in advance

              Thanks

              Venkat.

              (0) 
  3. Massimo Guarino

    Hi Sharadha,

    I’m still trying to set this application in Fiori Framework Page, but when I add the iview in the Framework page, the Landing Page is not displayed anymore, I only see the background, no menu bar, no Tiles are displayed.

    Immagine2.png

    Immagine.png

    Can you help me with this?

    Thanks in advance

    Massimo

    (0) 
  4. Amith Vandana

    Hi Sharadha,


    I have created Ideal Timeout as per your document, but it is not tracking user events in content area in sap portal 7.4.


    Please help me on this issue? how to track user events in content area.

    Thanks,

    Amith.


    (0) 
  5. Poojith M V

    Hi Sharadha,

    Thanks for blog. It is really helpful to me as I am also working on a similar requirement on Portal 7.4.

    I tried the same steps mentioned and currently stuck with 2 issues in each browser:

    IE 11:

    1. Preview of the IView does not show any event capture and the code does not seem to work.
    2. Using the IE developer tool, I could the see the error as belowIE11_Error.jpg

    Result: Not working in IE11

    Chrome:

    1. Preview working fine and all the events related to Keyboard & Mouse is captured and the counter is reset.
    2. Works fine when the session is left without any activity.

    However, I noticed that in spite of continuous movement of mouse and keyboard actions, the pop-up is displayed after 2 min and the Status value becomes 1.

    I tried several iterations and this was observed everytime.

    I am not much worried about the chrome browser, as the clients only use IE11 and it does not work there 🙁

    I am using the jquery-1.11.2.min.js file and IE version is 11 and portal version is 7.4. Screenshot for the IE error is attached as well.

    Please let me know if I am missing anything here?

    (0) 
    1. sam jon

      Hi Sharadha ,

      I am getting below error.

      error -componentRequest cannot be resolved

      Screen shot attached.pls help me.

      ty.PNG

      Regards,

      SAM

      (0) 
      1. Kamal j

        Hi Sam,

        add these two imports in your jsp file:

        <%@ page import = “com.sapportals.portal.prt.component.*”%>

        <%@page import=”com.sapportals.portal.prt.component.IPortalComponentRequest”%>

        Regards,

        Kamal

        (0) 
          1. Kamal j

            Hi Sam,

            you can ignore that error because during runtime it doesn’t affect your application(doesn’t throw any error). You can export your application as a war or ear and deploy on the portal.

            Regards,

            Kamal

            (0) 
              1. Kamal j

                Hi,

                Are you getting any error while exporting or you didn’t find option to export.

                Kindly attach the screenshots.

                Regards,

                Kamal

                (0) 
                  1. Kamal j

                    Hi,

                    is your project visible under Web project dropdown.

                    Try out in this way:

                    export your project as SAP Netweaver Portal ear file (refer the attched screenshot).

                    $532A85D90184B58D.jpg

                    in the next screenshot, choose your project and click on Next. Export it as an ear file and then deploy.

                    Regards,

                    Kamal

                    (0) 
                      1. Kamal j

                        Hi Sam,

                        in which perspective you developed this project? i.e. in web dynpro perspective as DC or in java EE perspective.

                        If you developed the project as a DC, you just have to deploy directly by right click on the project and choose deploy.

                        Regards,

                        Kamal

                        (0) 
                          1. Kamal j

                            Hi,

                            did you checked under portal applications by navigating to Content Administration–Portal Content—Portal Applications.

                            Under portal applications, you can find all the deployed enterprise portal applications.

                            And check under web dynpro java applications also under the same path.

                            Regards,

                            Kamal

                            (0) 
    2. Saravanan Sethumurugan

      Hi Sharadha/Poojith,

       

      Adding a new JS to the DC project solved the issue as “QuerySelector” is not available in IE11 by default as the compatibility mode points to IE 7.

      This is what needs to be done:

      1. add the attached JS to the script folder and in the DC code (https://gist.githubusercontent.com/Fusselwurm/4673695/raw/098334236211efe3d12d1084cada7000ef19d7e2/querySelector.js)
      2.  it will be look like this.

      <script type=”text/javascript” src=”<%=mimeUrl%>/scripts/queryselector.js”></script>
      <script type=”text/javascript” src=”<%=mimeUrl%>/scripts/jquery-1.11.2.min.js”></script>

      I have added and it is working as expected.

      Also I used in Portal version NW 7.30 and it is worked as expected.

      Regards,

      Sethu

      https://gist.githubusercontent.com/Fusselwurm/4673695/raw/098334236211efe3d12d1084cada7000ef19d7e2/querySelector.js

      (0) 
  6. Natalie Zhang

    Hi,

    First of all, thank you for the article.

    I followed the instruction, created the portal application package and deployed successfully to the server. I can see the page in the “content administration” -> “portal content management” -> “Portal applications”. Note: I can’t see it in “Web Dynpro Java Applications”.

    I copied the “TimeOut” dyn page and “pasted as PCD object” to the folder that i store iviews in “Portal Content” folder. Note: The iview created from template as “Web Dynpro application” gave me “resource does not exist” error.

    I added the iview to the customized Ajax framework page as “container for Technical Hidden iviews”.

    I changed the master rule to adopt the custom desktop which with custom ajax framework page.

    Logoff, clean browser cache, logged back in. Nothing happened after 2 min.

    I checked the browser F12. I can see the TimeOut div in the source. with error: “Object doesn’t support property or method ‘querySelector’ “

    Could you please help? Appreciated

    (0) 
  7. Suman Lal

    Hi All,

    I am getting below “Portal run time error”  after idle session while calling.

    window.location.assign(“/irj/servlet/prt/portal/prtroot/com.sap.portal.navigation.masterhead.LogOutComponent”);

     

    Thanks & Regards,

    Mallesh

     

    (0) 

Leave a Reply