Home
Analytics
How to get the maxuser / maximo username who requested the report?
joshhidley
I need to filter my report's data based on the Maximo user who requested the report. Specifically, I need to show only data which is related to the site the user is in.
I know how to do this if I could get the maxuser who requested the report. Is there a way to reliably get this?
I've figured out how to get it some of the time. The following code works when a report is requested for Immediate printing, but not if the report is scheduled and emailed.
var maxuser = reportContext.getHttpServletRequest().getParameter("userName")
The problem is that if it is scheduled and emailed then getHttpServletRequest() returns null (which makes sense).
Any ideas would be greatly appreciated.
Thanks,
Josh
Find more posts tagged with
Comments
AbbyNL
Josh,
If you are using V7.1 then an out of the box report will get you all the information you need for report usage. The reportusage.rptdesign groups reports by Application and displays Start Date, End Date, Run Time, User, Application, Scheduled, and Success. V7.1 has a database tables REPORT and REPORTUSELOG.
If you are in V6.x the parameter :user grabs the login user name to use in the Actuate report.
joshhidley
Thanks for the quick reply AbbyNL!
I am using Maximo 7.1 (BIRT 2.1.2).
I checked out the reportusage report and the REPORTUSAGELOG table and I think that's on the right track, but I'm not sure if that's exactly what I'm after.
I'm trying to retrieve the maximo user from within a report's code so I can use it to append to the where clause. I will put it in the DataSet's open event. Something like:
<code>
...
var userName = howDoIGetUserName();
where += " AND siteid = SELECT DEFSITE from MAXUSER WHERE USERID = '" + userName + "'";
...
</code>
I could query the USERID from the REPORTUSAGELOG table if I knew which row referred to the currently running report. Any ideas how to get that? Is the REPORTUSAGELOGID or ROWSTAMP passed into the report somehow?
Thanks for your help,
Josh
AbbyNL
Hi Josh,
Just playing with SQL I came up with a partial way to retrieve some information.
select Max(enterdate)as lastdt,reportusagelogid, reportname,userid
from reportusagelog
where appname='SR'
group by reportusagelogid, reportname, userid
If you know the appname, which I think is passed as a param, and the reportname I think you could use the Max(enterdate) to get the last entry into the table for the report and the userid.
I would need to play around with it some more but maybe that will give you a little bit more to spark a thought. If I get anything else I'll post it.
AbbyNL
You can use queries in the fetch() to grab additional data needed for the report. There is an example in the Report Developer Guide that shows how this would work. I think that might be the way to go to grab the userid.
Dragunov
I too have a similar requirement. My report is not a scheduled report. I need the login user siteid in the report parameter window of maximo by default. Any idea on how to get this? . Can we do some field level java customization to achieve this?
joshhidley
Thanks for getting me on the right path AbbyNL. Here's what I came up with. I think it covers all the bases.<br />
<br />
The problem is that the MAXUSER is available from the HttpServletRequest() when a report is run for Immediate printing, but if it's run "At this Time..." or Recurring, then you have to get it from the REPORTJOB table. One solution won't work for both situations.<br />
<br />
You can put the following code into your dataset's Open method and call it to return the MAXUSER who is requesting the report.<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
function getUserName(dataSourceName) {
var userName = null;
var hsr = reportContext.getHttpServletRequest();
if(hsr != null) {
var paramString = hsr.getParameter("parmParameterString");
// Just for debugging in Eclipse...
if(paramString == null)
paramString = "MaximoUserID=george||locale=en_US||mroYes=Y||mroNo=N||rsseAlias=null||multiServer=||reportDesc=PHYSICAL INVENTORY - Missing Physical Counts - NSN Sequence||MaximoUserID=george2||";
var paramDelimiter = hsr.getParameter("parmParameterStringDelimiter");
// Just for debugging in Eclipse...
if(paramDelimiter == null)
paramDelimiter = "||";
var key = "MaximoUserID=";
// These come out of getPrameter as objects and don't play well with string manipulation functions unless casted.
paramString = String(paramString);
paramDelimiter = String(paramDelimiter);
var start = paramString.lastIndexOf(key) + key.length;
if(start < 0)
return null;
var len = paramString.indexOf(paramDelimiter, start);
if(len < 0)
len = paramString.length;
userName = paramString.slice(start, len);
}
if(userName == null || userName == "") {
var reportJobId = mxReportScriptContext.getMXReportContext().get("REPORTJOBID");
if(reportJobId != null) {
var reportJobDS = MXReportDataSetProvider.create(dataSourceName, "reportJobDS");
reportJobDS.open();
var sql = "SELECT USERID FROM REPORTJOB WHERE REPORTJOBID = ?";
reportJobDS.setQuery(sql);
reportJobDS.setQueryParameterValue(1, reportJobId);
if(reportJobDS.fetch())
userName = reportJobDS.getString("USERID");
reportJobDS.close();
}
}
return userName;
}
</pre>
<br />
You can call this function with the following code:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
var myUserName = getUserName(this.getDataSource().getName());
</pre>
<br />
NOTE:<br />
In a previous post, I mentioned an unreliable way way to get the MAXUSER when a report is called for Immediate printing. The following didn't work reliably for me. I'm not sure why. Use the method above instead.<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
// The following is unreliable! Parse it out of parmParameterString instead.
reportContext.getHttpServletRequest().getParameter("userName")
</pre>
<br />
Also note that when this is called for Immediate printing, the user name seems to come back in lower-case even if that's not the correct case in MAXUSERS. If you're using a case-sensitive DB (Oracle's default), take that into consideration if you're using it in queries.<br />
<br />
I hope this helps,<br />
<br />
Josh
sdlemaster
This feature works like I want it to but now whenever I use the Direct Print feature in Maximo then the report prints out blank. When i take out the code handling the logged in user it prints just fine. Any ideas on why the logged in user code would break the direct print? Thanks.
joshhidley
I haven't tested it with Direct Print yet.
When Maximo calls a report using Direct Print, it's over http, so I think it should fall into the first "if" statement. It must not be passing the same http query parameters or something.
I figured out this solution by looking at the report log files to see what Maximo was passing when it called the same report in different ways. I won't have time to test this on Direct Print for a few weeks probably, but I will need it to work this way too eventually.
Are you appending the userName to your SQL where clause to limit the data? If so, then the reason you're report is coming out blank is might be that this code is not resulting in a user name and so your data is getting filtered to nothing.
Josh
zsarah
<blockquote class='ipsBlockquote' data-author="'sdlemaster'" data-cid="54486" data-time="1253812261" data-date="24 September 2009 - 10:11 AM"><p>
This feature works like I want it to but now whenever I use the Direct Print feature in Maximo then the report prints out blank. When i take out the code handling the logged in user it prints just fine. Any ideas on why the logged in user code would break the direct print? Thanks.<br /></p></blockquote>
Rani
<p>getUserName function working as expected for on-demand reports. It's returning blank report with direct print option. Please share, if any one find any solution.</p>
onthegomiller
<p>Was there ever a resolution found to the issue discussed in this thread regarding direct print rendering a blank page due to the getUserName function? I'm currently experiencing this issue and was wondering if anyone found an answer?</p>