If you are unable to create a new account, please email support@bspsoftware.com

 

News:

MetaManager - Administrative Tools for IBM Cognos
Pricing starting at $2,100
Download Now    Learn More

Main Menu

Pre populate values in Select & search prompt.

Started by CognosQ, 20 Sep 2017 08:23:10 AM

Previous topic - Next topic

CognosQ

We have to use Select & search prompt.
Requirement is that the Choices box should Pre populate all the values of the prompt parameter, even before the user enters the search string so that user can have a look on the list and then search accordingly in single select or multiselect.
Does anyone has any java script code to achieve this?


Thanks!

CognosPaul

Which version and how soon do you intend to upgrade?

CognosQ

Version - Cognos 10.2
Upgrade- May be in a year to Cognos Analytics.

CognosPaul

Okay, thing to remember is that any JS used in 10 will not work in interactive mode in Cognos Analytics.

Take a look at the attached report. I don't have C10, but it might work.

The JS is pretty basic:
<script>

var paulScripts ={}
, oCR = cognos.Report.getReport("_THIS_");


paulScripts.getControl = function(promptName) {
  return oCR.prompt.getControlByName(promptName);
};

paulScripts.loadSNSDefaults = function(SNSName,valueName){
  var SNS=paulScripts.getControl(SNSName)._id_
  , val = paulScripts.getControl(valueName)._id_
  , SNSSel = document.getElementById('PRMT_SV_'+SNS)
  , valSel=document.getElementById('PRMT_SV_' + val)
;

  if(sessionStorage['SNSDefault'+SNSName]) return true;

  for(var i=2;i<valSel.length;++i){
    SNSSel.options.add(valSel.options[i].cloneNode(true));
  }

  sessionStorage.setItem('SNSDefault'+SNSName,1)

};


paulScripts.loadSNSDefaults('companies','defaultCompanies');
</script>


You need two prompts, one is your SNS and the other being a value prompt that is loaded with your desired prompt objects. The script finds the actual select elements, and copies the options from the value to the SNS. Notice the loop starts at 2 to skip the prompt name and dashed line. After, you simply call the function with the names of the SNS and Value prompt.

To hide the value prompt, simply wrap them in <div style="display:name"> and </div>

CognosQ

Thank you so much for the reply! Will definitely try.

CognosQ

Hi Paul,

I tried your code, unfortunately it didn't work.
Could you please help me in understanding the code, may be my approach is wrong.

I copied the XML also, that you attached and change the prompt with desired prompt objects Objects - SNS & value prompt , reprompt button shown but it didn't pre-populate any thing.

I gave the name of my prompt :

SNS : companies
Value Prompt - defaultCompanies

Could you please tell me apart for the above name do I need to define anything?
promptName --?? which name it is trying to refer
SNSName?? which name it is referring as we already defined "companies" as our prompt name for SNS
valueName?? which name it is referring as we already defined "default companies" as our prompt name for value prompt
SNSDefault??

I understand the concept of copying value list into SNS but don't understand the code.

Thanks

CognosPaul

The only thing in the script you should change is the function call to loadSNSDefaults.

In the report you should have two prompts. The SNS and a value prompt that contains all of the values you want preloaded. The name of the prompts are what you put into the function. It looks like you're doing that.

The next thing to check, are you running the function before or after the prompt? Try moving the HTML item to after the prompt and see if that works.

CognosQ

#7
Hi,

I am running this script:
SNS Name : - companies
ValueName - default companies

<script>

var paulScripts ={}
, oCR = cognos.Report.getReport("_THIS_");


paulScripts.getControl = function(promptName) {
  return oCR.prompt.getControlByName(promptName);
};

paulScripts.loadSNSDefaults = function(companies,default companies){
  var SNS=paulScripts.getControl(companies)._id_
  , val = paulScripts.getControl(default companies)._id_
  , SNSSel = document.getElementById('PRMT_SV_'+SNS)
  , valSel=document.getElementById('PRMT_SV_' + val)
;

  if(sessionStorage['SNSDefault'+companies]) return true;

  for(var i=2;i<valSel.length;++i){
    SNSSel.options.add(valSel.options.cloneNode(true));
  }

  sessionStorage.setItem('SNSDefault'+companies,1)

};


paulScripts.loadSNSDefaults('companies','default companies');
</script>


********************************************

I have taken objects in this sequence
SNS prompt --- Value prompt---HTML ( Script )
I have highlighted the changes which I am trying. Am i doing anything wrong?


PS: Initially I didn't changed anything on script, just changed the SNS prompt name = 'companies' & Value prompt name = 'default companies'  on my report and copied the script as it is. Now thought to change as above, that also missing something.

CognosPaul

The only place you should change is:

paulScripts.loadSNSDefaults('companies','default companies');


by changing the function definition you're preventing it from working.

Also, can you confirm that this is placed AFTER the SNS and value prompts?

CognosQ

Hi Paul,

Yes, initially I didn't changed anything on script and kept the name of my prompt as given over here.

SNS : Companies
Value Prompt : default companies

Yes, the script is place AFTER SNS & value prompt same as you did in report xml. I just didn't use reprompt button

Sequence used:
SNS Prompt---Value Prompt---HTML item

Is still I am missing something?

CognosPaul

Post your report XML and I'll take a look.

CognosQ

Thanks for your reply. However, we did different approach.
We used TEXT prompt & Value prompt . Whatever the use entered in text prompt will get filtered on Value prompt ( using like or % filter in value prompt query)

Drawback - User needs to enter 2 times submit button.
Once a user submit, records get filtered for value in Value Prompt.
Second time when the user select value from Value prompt , the report get filtered.

radid8460

Hi Paul, I am able to make your code working but the problem is .. whenever I am searching and clicked on search button the field gets empty and no value comes to the window. could you please help me out..!!! I have attached my XML copy.. thanks 

radid8460

Hi Paul,

Its works after SNS parameter defined Query and Value... first time I forgot to assign them ... you are awesome and its helping me out of my problem . I was trying your XML to run in my Cognos11 but somehow I am getting error. but hopefully re prompt will help to refresh the value again . could you please tell me how I may refresh the prompt value again..!!! thanks for your help...