Cognos Analytics

Cognos Analytics

Connect, learn, and share with thousands of IBM Cognos Analytics users! 

 View Only
Expand all | Collapse all

Problem with Cognos report with JQuery

  • 1.  Problem with Cognos report with JQuery

    Posted Thu January 16, 2020 12:07 PM
    Edited by System Admin Fri January 20, 2023 04:18 PM
    Hello Everybody,

    When i put these line in a <HTML item> for use JQuery:

    <script src="https://code.jquery.com/jquery-3.4.1.js"></script>

    The auto-submit of value prompt don't work. I don't know what i can do for solve this problem because i want to use JQuery and auto-submit of the prompt.

    If i put and prompt button in the report with type Reprompt doesn't work either if the jquery line is still in the <HTML item>

    Thanks in advance.

    ------------------------------
    Robert Berchtold Palacios
    ------------------------------
    #CognosAnalyticswithWatson


  • 2.  RE: Problem with Cognos report with JQuery

    Posted Fri January 17, 2020 08:58 AM
    @Robert Berchtold Palacios Not sure what you are trying to accomplish with JQuery, but same as last post, try and move the HTML item after the prompt control? Does that work?


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



  • 3.  RE: Problem with Cognos report with JQuery

    Posted Mon January 20, 2020 05:14 AM
    @DENNY NAREZNY

    As we spoke in this post: Javascript Prompt Api dont work for my cognos 11 instance

    If i put the import line of the Jquery library, the Cognos Javascript API functions don't work and the prompts autosubmit property don't work either.

    If i delete the import line of the jquery library. The Cognos Javascript API functions works well and prompts can autosubmit but i can't use the jquery functions...

    This beahavior is the same if i put the html item in the right of the prompt control or in other places of the report.

    I want to use both in the same report, Jquery functions and Cognos Javascript API functions but i dont reach that both coexist.




    ------------------------------
    Robert Berchtold Palacios
    ------------------------------



  • 4.  RE: Problem with Cognos report with JQuery

    Posted Tue January 21, 2020 03:15 AM
    Try using noconflict:   https://api.jquery.com/jQuery.noConflict/


    ------------------------------
    Paul Mendelson
    ------------------------------



  • 5.  RE: Problem with Cognos report with JQuery

    Posted Tue January 21, 2020 04:16 AM
    Edited by System Admin Fri January 20, 2023 04:36 PM
    Thanks for your answer @Paul Mendelson .

    I try this code but the result is the same. If i import explicity the jquery library and after i put the noConflict code, the jquery works but some of cognos report funcionalities doesnt works. 

    We are discusin about this in this forum thread too: Javascript Prompt Api dont work for my cognos 11 instance

    In this forum thead, we discuss that the jquery library it's installed by default and working since we acces to the cognos portal, therefore, i try too put in the <html item> the noConflict code without before importig explicity the jquery library but, if i dont import explicity the jquery library, none jquery code works.



    ------------------------------
    Robert Berchtold Palacios
    ------------------------------



  • 6.  RE: Problem with Cognos report with JQuery

    Posted Tue January 21, 2020 05:13 AM
    1.) Using noConflict
    The noConflict one must be mapped differently. 

    var j$ = jQuery.noConflict();
    see: https://stackoverflow.com/questions/2731897/loading-jquery-twice-causes-an-error

    2.) See where jQuery is defined

    Here is a small script for testing. Just insert it into HTML-item.
    <div onmouseover="<div onmouseover="
    function amvara() { console.log('mouseover is active'); if (typeof jQuery == 'undefined') {                  console.log('jQuery is not defined in this window.');                  console.log(' We could go to parent scope or just load a new instance in the iFrame or window.'); if (typeof window.parent.$.fn.jquery == 'undefined' ) { console.log('There is really no jQuery loaded. So we are safe to load one ourselfs.'); } else { console.log('There is a jQuery in parent scope. So we can use that one.'); console.log(window.parent.$.fn.jquery);   }; } else { console.log(jQuery.fn.jquery); }; };  amvara();" void="v4" id="v4">
    ... hover me ... </div>
    I put that in HTML item and it perfectly looks for where the jQuery scope is.


    As the report is run in an iFrame but jQuery is loaded in the window.parent scope ... above script looks in parent scope as well.

    See console.log



    Sidenote:
    script-tags with function definitions are stripped out. 
    So, with the onload-tag of a blank gif you can come around this.

    Chars like "<" and ">" also.
    Use String.fromChar(60) + String.fromChar(62) for that 

    Does this work for you?


    ------------------------------
    Ralf Roeber
    Managing Partner
    Amvara Consulting
    El Masnou
    ------------------------------



  • 7.  RE: Problem with Cognos report with JQuery

    Posted Tue January 21, 2020 06:11 AM
    Edited by System Admin Fri January 20, 2023 04:11 PM
    Hi @Ralf Roeber,

    Y try your code and the output show me that 'There is a JQuery in parent scopre. So we can use that one.'.

    Does it means that the report have loaded the JQuery library but when we put the <html item> this item run in another scope and the JQuery don't load inside it? I dont understand in what place i need to put my jquery code for that it work well.

    I try this code but dont work:

    <div onmouseover="amvara();" void="v4" id="v4">... hover me ... </div>  

    <script>
    var object_slicer;
    var value_sel;
    var first_year = $("#sel_año select option:eq(2)").val();
    var last_year =  $("#sel_año select option:last-child").val();


    var object_slicer =  '<input id="obj_slicer" type="range" min="' + first_year + '" max="' + last_year  + '"/>';


    $("#container").append(object_slicer);


    $( "#obj_slicer" ).change(function() {


    value_sel = $( this ).val();
    $("#sel_año select").val(value_sel)
     
    });
    </script>




    This code get two years of an prompt,
    create a slicer html,
    insert the slicer in the report and finally set the value that the user choose in the slicer into the prompt.

    With the code above dont work. If i put implicity the jquery library works but the prompt autosubmit and other properties of it stop working.


    Salutacions desde Sant Cugat :)


    ------------------------------
    Robert Berchtold Palacios
    ------------------------------



  • 8.  RE: Problem with Cognos report with JQuery
    Best Answer

    Posted Tue January 21, 2020 07:09 AM
    Edited by System Admin Fri January 20, 2023 04:13 PM

    >Does it means that the report have loaded the JQuery library but when we put the <html item> this item run in another scope and the JQuery don't load inside it?
    Not exactly.
    jQuery is loaded. Yes.
    The scope depents on how the report is run.
    From the editor it normally opens in an iFrame. This is why the scope is above in window.parent.

    >I dont understand in what place i need to put my jquery code for that it work well.

    Added some lines to your script quick and dirty:

    <script>

    var myJquery;

    if (typeof jQuery == 'undefined') {
       console.log('jQuery is not defined in this window.');
       console.log(' We could go to parent scope or just load a new instance in the iFrame or window.');
       if (typeof window.parent.$.fn.jquery == 'undefined' ) {
          console.log('There is really no jQuery loaded. So we are safe to load one ourselfs.');
       } else {
          myJquery = window.parent.$;
          console.log('There is a jQuery in parent scope. So we can use that one.');
          console.log(window.parent.$.fn.jquery); }; }
    else {
        console.log(jQuery.fn.jquery); };
        myJquery = jQuery;
    };

    if (typeof myjQuery == 'undefined') {
        console.log('Houston, we have a problem. Might want to load jQuery first.')
    }



    var object_slicer;

    var value_sel;

    var first_year = myJquery("#sel_año select option:eq(2)").val();

    var last_year =  myJquery("#sel_año select option:last-child").val();

    var object_slicer =  '<input id="obj_slicer" type="range" min="' + first_year + '" max="' + last_year  + '"/>';

    myJquery("#container").append(object_slicer);

    myJquery( "#obj_slicer" ).change(function() {

    value_sel = myJquery( this ).val();

    myJquery("#sel_año select").val(value_sel)

     

    });

    </script>

    Hope that helps.

    Grüße aus Masnou ;-)

    ------------------------------
    Ralf Roeber
    Managing Partner
    Amvara Consulting
    El Masnou
    ------------------------------



  • 9.  RE: Problem with Cognos report with JQuery

    Posted Tue January 21, 2020 10:01 AM
    Edited by System Admin Fri January 20, 2023 04:38 PM
    @Ralf Roeber

    Thanks for your quick answer again. I try your code but something is wrong initiallitiating the JQuery.​ The output of the console show this:


    This is the code that i try (only the initialitatin part):


    ------------------------------
    Robert Berchtold Palacios
    ------------------------------



  • 10.  RE: Problem with Cognos report with JQuery

    Posted Tue January 21, 2020 12:12 PM
    if (typeof myjQuery == 'undefined') {
        console.log('Houston, we have a problem. Might want to load jQuery first.')
    }

    to

    if (typeof myJquery == 'undefined') {
        console.log('Houston, we have a problem. Might want to load jQuery first.')
    }


    ------------------------------
    Ralf Roeber
    Managing Partner
    Amvara Consulting
    El Masnou
    ------------------------------