Cognos Analytics

 View Only
  • 1.  Grabbing Selected Prompts Values Using JS

    Posted Fri March 22, 2019 03:50 PM
    Edited by System Fri January 20, 2023 04:38 PM
    ​​Hi,

    I'm looking for a way let users click the 'Finish' button and have the report open in a new tab as it seems that functionality was removed from C10 to CA.
    I'm attempting to add it back using JavaScript and I'm currently able to construct a URL with variables concatenated to it in order to let the user click the link and have the report run as desired. This only works with pre-defined variables as of right now since I am having trouble grabbing the selected values and storing them.

    Current Code: Underlined code does not work and is possibly not the correct approach

    <button class="button" onclick="runReport()">Finish</button>
    <script>
    function runReport(){
    var report = cognos.Report.getReport("_THIS_");

     var aPrompt = report.prompt.getControlByName(<prompt name>);
     var dPrompt = report.prompt.getControlByName(<prompt name>); 
     var a = aPrompt.prompt.getValues()[0];
     var d = dPrompt.prompt.getValues()[0];
    window.open("cognos...filepath...promptA=a&promptD=d"); <--- Works if a and d are constant variables
    }
    </script>

    Additional Info:
    • I do not want the prompts to be auto submitted as this will run the report after the prompts are selected
    • I've tried using a hyperlink item with drill-through but this also requires auto submit


    ------------------------------
    Anthony Landati
    ------------------------------

    #CognosAnalyticswithWatson


  • 2.  RE: Grabbing Selected Prompts Values Using JS

    Posted Wed March 27, 2019 10:34 AM

    Hey Anthony,

    Let me do a bit of investigation on this. I will try and get back to you early next week.



    ------------------------------
    DENNY NAREZNY
    ------------------------------



  • 3.  RE: Grabbing Selected Prompts Values Using JS

    Posted Wed March 27, 2019 01:38 PM
    ​Thank you Denny, I will be patiently awaiting your response.

    ------------------------------
    Anthony Landati
    ------------------------------



  • 4.  RE: Grabbing Selected Prompts Values Using JS

    Posted Wed March 27, 2019 04:15 PM
      |   view attached
    Hey Anthony,
    Try the below Javascript. I've also attached a sample report spec.

    *Javascript provided as is*

    <script type="text/javascript">
    function runReport() {
    var oCR = cognos.Report.getReport("_THIS_");

    var promptProduct= oCR.prompt.getControlByName("Product");
    var promptYear= oCR.prompt.getControlByName("Year");

    var Product = promptProduct.getValues()[0].display;
    var Year = promptYear.getValues()[0].display;

    window.open("http://ibmdemo.ibm.com:10913/bi/?pathRef=.my_folders%2FIBM+JS+Prompt+Report&format=HTML&Download=false&prompt=false&p_Product="+ Product + "&p_Year=" + Year);
    }
    </script>
    <input type="button" value="Finish" onclick="runReport()">

    ------------------------------
    DENNY NAREZNY
    ------------------------------

    Attachment(s)

    txt
    IBM JS Drill-through.txt   8 KB 1 version


  • 5.  RE: Grabbing Selected Prompts Values Using JS

    Posted Fri March 29, 2019 09:13 AM
    Thank you so much,
    I guess something as little as an array index and .display was enough to make this work.
    ​.getValues()[0].display;

    ------------------------------
    Anthony Landati
    ------------------------------