COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: raja_krp on 29 Aug 2016 06:37:23 AM

Title: Cognos 10 - Assign logged User Name to a parameter using Javascript
Post by: raja_krp on 29 Aug 2016 06:37:23 AM
Hell Team,

How to assign the user name using to a parameter using Java script so that that parameter can be used in calculations.

Thanks...
Title: Re: Cognos 10 - Assign logged User Name to a parameter using Javascript
Post by: AnalyticsWithJay on 29 Aug 2016 07:04:20 AM
There's already a parameter for username. You don't need to use anything to assign it to a parameter.


#sq($account.personalInfo.userName)#
Title: Re: Cognos 10 - Assign logged User Name to a parameter using Javascript
Post by: raja_krp on 29 Aug 2016 07:27:13 AM
Thanks for your response.

We are using (#sq($account.personalInfo.userName). But need Java script code to assign it to a parameter.
Title: Re: Cognos 10 - Assign logged User Name to a parameter using Javascript
Post by: AnalyticsWithJay on 29 Aug 2016 09:31:48 AM
Hi Raja,

I see your other post about this parameter and substring() with MDX. I assume you're looking to pass the substring value as a parameter, which makes sense to me now.

There are a couple of solutions for this. A good starting point that outlines these solutions is the following page:
http://cognosknowhow.blogspot.ca/2013/04/how-to-dynamically-set-up-default-value.html?cm_mc_uid=44957120532814660888625&cm_mc_sid_50200000=1472480762

Once you start with a solution, let me know if you run into issues with the javascript and I can help out.
Title: Re: Cognos 10 - Assign logged User Name to a parameter using Javascript
Post by: raja_krp on 29 Aug 2016 10:27:41 AM
Thanks Jai,

You are correct my posts are related. I will try the solution that you have recommended.

Have fun,
Raj
Title: Re: Cognos 10 - Assign logged User Name to a parameter using Javascript
Post by: raja_krp on 29 Aug 2016 07:50:30 PM
Hello Jay,

I am stuck at passing a macro value, user ID, to a variable in Javascript that is meant to pass value to a value prompt?

Please help

Thanks,
Raj
Title: Re: Cognos 10 - Assign logged User Name to a parameter using Javascript
Post by: AnalyticsWithJay on 30 Aug 2016 09:48:19 AM
Quote from: raja_krp on 29 Aug 2016 07:50:30 PM
Hello Jay,

I am stuck at passing a macro value, user ID, to a variable in Javascript that is meant to pass value to a value prompt?

Please help

Thanks,
Raj

I wrote and tested this right now using a text box prompt. The Name property of the prompt is 'JayPrompt'.


<script type= "text/javascript">

var oCR = cognos.Report.getReport("_THIS_");
var oP = oCR.prompt. getControlByName( 'JayPrompt' );

oValues = [{'use': 'Jay', 'display': 'Jay'}];
oP.addValues( oValues );

</script>


Take a look in my recent post history for JavaScript posts. I recently helped someone get a value from a hidden DIV on the page to use in JavaScript. You will need to do the same to get the username and use it in the oValues JavaScript variable above.

Note: Tested in 10.1.1. As always, exercise caution with use of JavaScript, as upgraded reports are not guaranteed to work in future releases of Cognos (Prompt API could change).

Jay
Title: Re: Cognos 10 - Assign logged User Name to a parameter using Javascript
Post by: dougp on 30 Aug 2016 12:04:43 PM
You didn't state a business requirement, you stated a technical solution.  Step back for a minute.

Are you sure you need to set the value of a parameter?  How about just using the results from the macro expression directly in a filter or case statement, as if it is the parameter?
Title: Re: Cognos 10 - Assign logged User Name to a parameter using Javascript
Post by: cognostechie on 30 Aug 2016 12:33:11 PM
Yes ! 

@ raja_krp - What's the purpose of the parameter? To set security in the report?
Title: Re: Cognos 10 - Assign logged User Name to a parameter using Javascript
Post by: AnalyticsWithJay on 30 Aug 2016 12:48:47 PM
Quote from: cognostechie on 30 Aug 2016 12:33:11 PM
Yes ! 

@ raja_krp - What's the purpose of the parameter? To set security in the report?

The issue is in his post history here:
http://www.cognoise.com/index.php/topic,31415.msg102353.html#msg102353
Title: Re: Cognos 10 - Assign logged User Name to a parameter using Javascript
Post by: cognostechie on 30 Aug 2016 12:58:54 PM
In that case, I don't want to comment on this as I do not support these kind of workarounds. The right way to do it would be to get the proper name in
the cube itself. Hardcoding the 'M' in the report could result in wrong data if the user name changes later on.
Title: Re: Cognos 10 - Assign logged User Name to a parameter using Javascript
Post by: CogDevloper on 30 Aug 2016 04:02:24 PM
@Jay & Raja
I have also received a similar kind of requirement.
Let me provide a brief description of my requirement.
I have got a report where there is Prompt named User Name,Client wants that whoever logs in and try to execute that report his Username should automatically gets captured in that Username Prompt.
Thereafter the report gets filtered and shows the record related to that user.

I would appreciate if either of you or anybody can provide me the step by step details on what needs to be done to meet this requirement.

Gracias
Vinny
Title: Re: Cognos 10 - Assign logged User Name to a parameter using Javascript
Post by: AnalyticsWithJay on 31 Aug 2016 06:38:51 AM
Quote from: CogDevloper on 30 Aug 2016 04:02:24 PM
@Jay & Raja
I have also received a similar kind of requirement.
Let me provide a brief description of my requirement.
I have got a report where there is Prompt named User Name,Client wants that whoever logs in and try to execute that report his Username should automatically gets captured in that Username Prompt.
Thereafter the report gets filtered and shows the record related to that user.

I would appreciate if either of you or anybody can provide me the step by step details on what needs to be done to meet this requirement.

Gracias
Vinny

Hi Vinny, it's best to start your own thread. You'll need to use a Macro Prompt with a default value of the username parameter. Set the filter to optional.