Skip to Content
Author's profile photo Sharadha Krishnamoorthy

Portal User Idle time out – NW Portal 7.4

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.

Assigned Tags

      43 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Sharadha K in SAP Enterprise Portal on Jul 27, 2015 5:12:57 PM


      Hi Sharadha,


      I have the same idle requirement, I tried to applied your code, but it does not work.

      I have created the iview, but from the preview I have some errors.



      Immagine.png


      Can you help me?

      Author's profile photo Sharadha K
      Sharadha K
      Blog Post Author

      Hi Massimo,

      It seems you have not added the Jquery file to the project under /scripts folder. Please download the jquery-1.11.2.min.js from the link below and add it under /scripts folder.

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

      This will solve the issue.

      regards,

      Sharadha

      Author's profile photo Former Member
      Former Member

      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

      Author's profile photo Sharadha K
      Sharadha K
      Blog Post Author

      Massimo,

      Can you get a screenshot of  the console log?

      -Sharadha

      Author's profile photo Former Member
      Former Member

      Immagine4.png

      I have another question, where I can change the "time out" popup to have only the button 'ok'?

      Thanks

      Massimo

      Author's profile photo Sharadha K
      Sharadha K
      Blog 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

      Author's profile photo Former Member
      Former Member

      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

      Author's profile photo Former Member
      Former Member

      Nice work!! It is very helpful

      Author's profile photo meghal shah
      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

      Author's profile photo Sharadha K
      Sharadha K
      Blog Post Author

      HI Meghal,

      you missed a '/' after <%mimeurl%> and before dist. Add it and check please.

      Sharadha

      Author's profile photo meghal shah
      meghal shah

      Hi Sharadha,


      Thanks for support.

      I got the issue.

      Problem has been resolved now.


      Regards,

      Meghal Shah


      Author's profile photo Former Member
      Former Member

      Nice Approach !!

      Author's profile photo Former Member
      Former Member

      Hi Sharadha,


      Thanks so much for sharing this useful implement . 🙂


      Have a nice day,


      Good luck,

      Sokmeng

      Author's profile photo Former Member
      Former Member

      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

      Author's profile photo meghal shah
      meghal shah

      Hi Venkat ,

      There is no application related Issue.

      Check your deployment connection with System DP1.

      check all the respective port is open or not .

      Check thread Unable to Deploy using NWDS

      Thanks & Regards,

      Meghal Shah

      Author's profile photo Former Member
      Former Member

      Hi Meghal Shah,


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


      Please help me


      Thanks

      Venkat

      Author's profile photo Former Member
      Former Member

      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.

      Author's profile photo meghal shah
      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

      Author's profile photo Former Member
      Former Member

      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

      Author's profile photo Former Member
      Former Member

      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.

      Author's profile photo Former Member
      Former Member

      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

      Author's profile photo Amith Vandana
      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.


      Author's profile photo Poojith M V
      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?

      Author's profile photo sam jon
      sam jon

      Hi Sharadha ,

      I am getting below error.

      error -componentRequest cannot be resolved

      Screen shot attached.pls help me.

      ty.PNG

      Regards,

      SAM

      Author's profile photo Former Member
      Former Member

      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

      Author's profile photo sam jon
      sam jon

      Thanks Kamal...

      I have added two import in js file but still getting error..pls help.

      time.PNG

      Regards,

      SAM

      Author's profile photo Former Member
      Former Member

      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

      Author's profile photo sam jon
      sam jon

      Hi,

      I unable to export war/ear file.

      cn u pls help me.

      Regards,

      SAM

      Author's profile photo Former Member
      Former Member

      Hi,

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

      Kindly attach the screenshots.

      Regards,

      Kamal

      Author's profile photo sam jon
      sam jon

      Hi,

      yes..error.

      pls find screen shot.

      w1.PNG

      w2.PNG

      Author's profile photo Former Member
      Former Member

      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

      Author's profile photo sam jon
      sam jon

      Hi kamal,

      I have gone through but unable to see any project for next button click.pls help

      er1.PNG

      Regards,

      SAM

      Author's profile photo Former Member
      Former Member

      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

      Author's profile photo sam jon
      sam jon

      Hi Kamal,

      I hv developed project in

      Enterprise Portal Perspective

      ,hv deployed but getting error and unable to find deployed object.

      Below is the error screen shot.pls help

      dep1.PNG

      Regards,

      SAM

      Author's profile photo Former Member
      Former Member

      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

      Author's profile photo Former Member
      Former Member

      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

      Author's profile photo Former Member
      Former Member

      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

      Author's profile photo Suman Lal
      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

       

      Author's profile photo navya shetty
      navya shetty

      Hi Sharadha,

      As per this blog, once the popup is displayed and the user does not click on OK and cancel, user continues to be on the same page.Additionally , if the user clicks  the mouse but does not click on OK or Cancel button, the timer is reset even though the user has not performed any activity on webpage.Is there any way to override the popup and force logout in such situation .

       

       

      Regards,

      Navya

      Author's profile photo Dharmaraj Arumugam
      Dharmaraj Arumugam

      Hi Sharatha,

      I have applied the same logic(which you given above code ex) in ajax standard framework page in our portal (ver 7.4). but i am getting the idle timeout pop up even though portal session is active and navigating to different roles and iviews. other functionality cancel Ok is working fine

       

      Regards,

      Dharmaraj A

      Author's profile photo Rodrigo Girlando
      Rodrigo Girlando

      Hi Dharmaraj

       

      I have implemented the solution as described in the blog but I had to change a little the logic of the script since, same as you,  I was getting the pop up all the time even though user was still active. In my case I had to logoff user after 30 minutes of inactivity, so I capture the time of the last user action (click, move move, key press) and then I compare it with the current time. If it is more than 30 min I trigger the portal logoff.

      it is working for now.

      Hope it helps

       

      Best regards!

      Rodrigo

      Author's profile photo Dharmaraj Arumugam
      Dharmaraj Arumugam

      Hi Rodrigo Girlando,

      Thanks for your prompt response. I have slightly changed the code as below and its started working fine.

      <HTML>
      <head>
      <% String mimeUrl = componentRequest.getWebResourcePath(); %>
      <script type="text/javascript" src="<%=mimeUrl %>/scripts/jquery-1.11.3.min.js"></script>
      <script type="text/javascript" >
      var idleTime = 0;
      $(document).ready(function () {
      idleInterval = setInterval(timerIncrement, 60000);
      $('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 + "key press";
      });
      });

      function timerIncrement() {
      idleTime = idleTime + 1;
      document.querySelector('.content .value').innerHTML = idleTime;
      if(idleTime > 5 ) {
      if(confirm('Your session is inactive for the last 5 minutes. Press OK to log off. Press cancel to continue 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>

       

      Author's profile photo Manish Gupta
      Manish Gupta

      Hi Dharmaraj Arumugam,

      I am using the same code, but in my case the popup itself is not coming even if user is idle for 2 minutes, 5 minutes.. Could you please help?

      Regards

      Manish Gupta