Cognos Analytics

Cognos Analytics

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

 View Only
Expand all | Collapse all

Javascript Prompt Api dont work for my cognos 11 instance

  • 1.  Javascript Prompt Api dont work for my cognos 11 instance

    Posted Thu January 16, 2020 11:19 AM
    Hello Everybody,

    I have a problem with the Javascript prompt API.

    I created a value prompt where i set in the Name property "paño".

    When i put a <HTML item> the next code:

    var report = cognos.Report.getReport( "_THIS_" )
    var control = report.prompt.getControlByName('paño');
    alert(control);

    After this i RUN the report in HTML mode. Once the report is render, the popup that generate the alert() code shows NULL .

    I dont understand what is the problem about this..the code initially is correct.

    PD: The report is runnin with full interactivity in "NO"

    Thanks in advance.

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

    #CognosAnalyticswithWatson


  • 2.  RE: Javascript Prompt Api dont work for my cognos 11 instance

    Posted Fri January 17, 2020 08:55 AM
    @Robert Berchtold Palacios It might be the placement of the HTML object. Try placing the HTML item it to the right of the value prompt ​. If that does not work, could you attach a copy of your report spec?

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



  • 3.  RE: Javascript Prompt Api dont work for my cognos 11 instance

    Posted Mon January 20, 2020 03:15 AM
    Edited by System Admin Fri January 20, 2023 04:45 PM

    @DENNY NAREZNY Thanks for your answer.

    I put the HTML object on to the right of the prompt and doesn't works either. 

    The alert() Javascript function displays NULL because the object isn't inicialliced. The instructions of Cognos Javascript API that i put in the previous images it should have iniciallized the object.

    Something is wrong, possibly the code or it is a bug of 11.1 R4 Cognos Analytics version

    Best Regards.

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



  • 4.  RE: Javascript Prompt Api dont work for my cognos 11 instance

    Posted Mon January 20, 2020 04:38 AM
    @DENNY NAREZNY

    I saw that if i delete the jquery import library, the Cognos Javascript API works well. But, if i put the jquery import library code, the jquery works well but the Cognos Javascript Api doesn't work.



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



  • 5.  RE: Javascript Prompt Api dont work for my cognos 11 instance

    Posted Mon January 20, 2020 08:35 AM
    @Robert Berchtold Palacios Thanks Robert. I will check with our team internally to see if this is expected behaviour. What version of Cognos Analytics are you using?

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



  • 6.  RE: Javascript Prompt Api dont work for my cognos 11 instance

    Posted Mon January 20, 2020 09:18 AM
    Edited by System Admin Fri January 20, 2023 04:31 PM
    @DENNY NAREZNY

    Thanks for your quick answer. I'm testing in a IBM cloud skylap virutal machine and the Cognos Analytics version installed in this cloud machine is 11.1 R4.


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



  • 7.  RE: Javascript Prompt Api dont work for my cognos 11 instance

    Posted Tue January 21, 2020 02:37 AM
    Hi, 
    I am having same problem when I try to use jQuery in a custom view extension. I am creating a custom landing page view where I needed to use Jquery library, Jquery UI library and jquery cookie plugin. I am able to use jqueryUI library by including it in script tag but as soon as I include jquery library many features of cognos stop working. I see that cognos installation folders have Jquery included in it; is there a way to use them by referencing them in our code in some way? 

    I am on cognos analytics v11.0.11.

    ------------------------------
    Kiran Passumarthi
    www.linkedin.com/in/kiranpassumarthi
    ------------------------------



  • 8.  RE: Javascript Prompt Api dont work for my cognos 11 instance

    Posted Tue January 21, 2020 02:55 AM
    Cognos loads jQuery when the user open the portal - 11.1.5 loads version 2.0.3.

    This being said, you will encounter any kind of problems loading another version on top.

    Try opening a webdeveloper console and look for the loaded version by typing:
    console.log(jQuery.fn.jquery)

    see also Cognos Installation path:

    root@x:/opt/IBM/cognos/crn0 : find ./ -name jquery.js | grep -i "jquery/"

    ./webcontent/bi/lib/jquery/3.3.1/jquery.js


    See also:
    https://stackoverflow.com/questions/2731897/loading-jquery-twice-causes-an-error

    Hope this helped.

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



  • 9.  RE: Javascript Prompt Api dont work for my cognos 11 instance

    Posted Tue January 21, 2020 03:05 AM
    Hi, 

    Thanks for the quick reply. I do see v2.0.3 in console in 11.0.11 version. And I see 2.1.1 folder in webcontent/bi/lib/jquery folders. Not sure why there is a mismatch but that aside, when I don't explicitly reference via script in the extension, I am unable to get jquery methods working. I even tried leaving out referencing jquery library but adding jquery cookie plugin reference to use cookie collection in jquery but that also doesn't work. The error message shows that I have to import jquery library before the plugin is used. Is there any documentation that talks about how to use ($ vs jQuery vs something else) to reference jquery objects without explicitly importing the library?

    ------------------------------
    Kiran Passumarthi
    www.linkedin.com/in/kiranpassumarthi
    ------------------------------



  • 10.  RE: Javascript Prompt Api dont work for my cognos 11 instance

    Posted Tue January 21, 2020 03:49 AM
    Thanks for all the answers.

    In my case, the web developer console show me that 3.3.1 is working and i have the 3.3.1 folder in the path webcontent/bi/lib/jquery but, like @Kiran Passumarthi  , if i dont import explicity the jquery library  in a <html item>,  the jquery code doesn't works. But, if i explicity import the jquery library , the jquery code works but some functionalities of cognos report as prompts autosubmit property, dont work.



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



  • 11.  RE: Javascript Prompt Api dont work for my cognos 11 instance
    Best Answer

    Posted Tue January 21, 2020 07:45 AM

    > Is there any documentation that talks about how to use ($ vs jQuery vs something else) to reference jquery objects without explicitly importing the library?

    They both do the same thing. Most Libraries use $ as a shorter way to access functions within the libraries.
    if you are using more then one javascript library there can be conflicts if you just use the $. using jQuery will avoid those.

    see:
    https://stackoverflow.com/questions/3291680/jquery-syntax-when-to-use-dollar-vs-jquery

    > if i dont import explicity the jquery library  in a <html item>,  the jquery code doesn't works
    Have a closer look at the scope, where the jQuery was loaded. Your report is probably running in an iFrame where there is no jQuery.
    In the top window (Cognos itself) jQuery was loaded. So you can access it as window.parent.$

    In order to execute your report and make it work in iFrame or without iFrame, you must check on the scope where jQuery is available.

    See related post for example code:
    Problem with Cognos report with JQuery



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