This is an example of using a javascript function in a Cognos Report Studio report to get the current user.
- Create a new report in Cognos Report Studio
- Create a new prompt page and add a HTML item control to the page.
- Add the following .js code to the HTML item
- When the form loads you should see an alert box with the current logged in username
<script>
function init(){
getFormElements()
}
function getFormElements(){
for (i=0; i<document.forms["formWarpRequest"].elements.length; i++){
if(document.forms["formWarpRequest"].elements[i].name == "ui.username"){
alert('THIS IS THE USER: ' + document.forms["formWarpRequest"].elements[i].value);
}
}
}
</script>
<body onLoad=init()>