October 21, 2013

Automatically refresh StartCenter

Users that heavily rely on StartCenters to check for incoming tickets or work orders sometimes ask if the StartCenter can automatically refresh itself.

To accomplish this you can inject a small JavaScript into the StartCenter JSP code.
Backup [SMPDIR]\maximo\applications\maximo\maximouiweb\webmodule\webclient\components\startcenter-options.jsp file and open it with a text editor.
Search for a row like this

<table ...

Add the following code just before that row.

<!-- BEGIN StartCenter automatic refresh -->
<script type="text/javascript">
  setTimeout("location.reload(true)", 60000);
</script>
<!-- END StartCenter automatic refresh -->

The refresh time in the previous script is in milliseconds so 60000 means 1 minute.

Rebuild and redeploy Maximo EAR file.

Now your start center will be automatically refreshed every 2 minutes.

Maximo 7.5 has introduced an exit warning so you may be prompted with a warning like this every minute.


To avoid this you can disable the exit warning as described in this TechNote.

Be careful when deciding how to set the refresh interval because setting it too low may impact overall system performances.

If this technique is not working you could look at this thread.

Enable autorefresh for one user group

A fellow Maximo consultant has applied this technique only to one user group using the following code.

<%@ page import="psdi.webclient.beans.startcntr.*" %>
<% 

try 
{
  SessionContext sessionContext = new SessionContext(wcs);
  StartCenterAppBean startcenter = (StartCenterAppBean)sessionContext.getCurrentApp().getAppBean();
  psdi.mbo.MboRemote mbo = startcenter.getMbo();
  String where = "groupname = '[GROUPNAME]' and userid in (select userid from maxuser where personid = '" + mbo.getUserInfo().getPersonId() + "')";
  psdi.mbo.MboSetRemote groups = mbo.getMboSet("$GROUPUSER", "GROUPUSER", where);
  groups.moveFirst(); 

  if ( !groups.isEmpty() ) 
  {
%>
    <script type="text/javascript"> setTimeout('window.location=window.location' ,10000); </script>
<% 
  } 
} 

catch (Exception e) 
{
  e.printStackTrace(); 
}
%>

The [GROUPNAME] must be replaced with the security group for which you want to enable the start center autorefresh.

Update
JedrekWiehas suggested to modify the script to set the session id in order to avoid duplication os user's sessions.

String refreshUrl = wcs.getMaximoRequestURI()
                  + "?event=loadapp&value=startcntr&"
                  + wcs.getUISessionUrlParameter()
                  + wcs.getCSRFTokenParameter();
%>
<script type="text/javascript"> setTimeout('window.location=window.location' ,10000); </script>
<% 



7 comments:

  1. Hello,

    recently I faced similar requirement - refresh Start Center every minute for specific user.
    I followed your instruction and it almost worked... After several auto-refreshes unfortunately Maximo started to reply with HTTP 503 error "You have reached the maximum number of sessions allowed for a user."
    After some investigation I noticed that once user logs in he's forwarded rather than redirected to Start Center. It means browser URL address remains http:///maximo/ui/login. When you periodically start to issue JS "window.location=window.location" then every time request reaches server new user UI session is created and eventually mxe.webclient.maxUISessionsPerHttpSession is exceeded.
    In order to avoid creating new UI session within the same web session you need to make sure that URL contains uisessionid query parameter. Actually there is one more URL query parameter called csrftoken that shall be rewritten as well.
    So the final solution looked as follows:

    psdi.security.UserInfo ui = wcs.getUserInfo();
    if (ui.getUserName().equals("MAINTVIEW")) {
    String refreshUrl = wcs.getMaximoRequestURI() + "?event=loadapp&value=startcntr&" + wcs.getUISessionUrlParameter() + wcs.getCSRFTokenParameter();
    // [script type="text/javascript"]setTimeout('window.location=""', 60000);[/script]
    }

    I hope this will let to avoid some of you the same problem I faced.

    BTW: I'm sorry but I couldn't parte scriptlet into the blogspot comment window so pay attention that sample script above requires tiny modification to actually output commented line as a part of HTTP response.

    ReplyDelete
    Replies
    1. Thank you Jedrek !
      I have updated the post.

      Delete
  2. This comment has been removed by the author.

    ReplyDelete
  3. How to configure the same in INCIDENT application

    ReplyDelete
  4. Thank you all for your input, I have tried the above solution in IBM Control Desk, but I found that 'window.location=window.location' resulted in a maximum number of sessions error. Therefore I tried location.reload(true).

    It looks like the first option only refreshes the content of the start center result sets etc. , the second option does a full refresh of the page, so the screen flickers for a second.

    For now I have this working with this code, I have included a few lines above the code to show the exact position, just paste it above the table tag:

    if(component.needsRender())
    {
    %>

    <%
    String refreshUrl = wcs.getMaximoRequestURI()
    + "?event=loadapp&value=startcntr&"
    + wcs.getUISessionUrlParameter()
    + wcs.getCSRFTokenParameter();
    %>
    [script type="text/javascript"> setTimeout('location.reload(true)' ,60000); [/script>



    Same as Jedrek, replace the [ with a < !!

    ReplyDelete
  5. I still received the error of maximum number of sessions. Changing the system property mxe.webclient.allowURLDefinedUISessionID to 1, the same UISession will be used. The downside is that this disables the ability to simply cut and paste the URL between tabs.

    Set it to 0, the uisessionid parameter in the URL will be ignored and a new Session is created.

    ReplyDelete