COGNOiSe.com - The IBM Cognos Community

IBM Cognos Analytics Platform => Cognos Analytics => Reporting => Topic started by: Blue on 31 Oct 2016 05:14:04 PM

Title: Custom control - Javascript error with getControlByName()
Post by: Blue on 31 Oct 2016 05:14:04 PM
G'day all

I have a JS error on a report that I can't figure out.  I would appreciate any guidance as my JS knowledge/experience is in need of enhancement :)

TypeError: oPage.getControlByName(...) is null
http://certuscogrpt01:9305/bi/samples/meridian/MenuBar/MenuBar.js
122

The are two custom controls to manage menu tabs.  E.g.:

(see attachment for CC JSON)

The one in question is MenuBar.  Below is a snippet of the JS where the error is occurring:

  MenuBar.prototype.f_bind = function (iCardIndex, oControlHost)
  {
    for ( var i = 0; i < this.m_nlButtonDivs.length; i++ )
    {
      var div = this.m_nlButtonDivs.item( i );
      //div.classList[( i == iCardIndex ) ? "add" : "remove"]( "selected" );
      if ( !this.m_bSetupEventHandlers )
      {
        div.onmousedown = this.f_displayCard.bind( this, i, oControlHost );
      }
    }
   var oPage = oControlHost.page;
    var oParameter = oControlHost.getParameter( "p_View" );
    var sParameterValue = ( oParameter && ( oParameter.values.length > 0 ) ) ? oParameter.values[0].use : "";
    if (sParameterValue == "stationlist")
    {
      console.log(sParameterValue);
      for ( var i = 0; i < this.m_sCardNames.length; i++ )
      {
        console.log(i);
        console.log(this.m_sCardNames);
        if (this.m_sCardNames=="stationlist")
        {
          this.m_nlButtonDivs.item(i).classList.add("selected");
          oPage.getControlByName("stationlist").setDisplay(true);
          oPage.getControlByName("stationview").setDisplay(true);
        }
        else
        {
          oPage.getControlByName( this.m_sCardNames ).setDisplay(false);
        }
      }
    }
    else
    {
      console.log(sParameterValue);
      for ( var i = 0; i < this.m_sCardNames.length; i++ )
      {
        console.log(i);
        console.log(this.m_sCardNames);
        this.m_nlButtonDivs.item(i).classList[( i == iCardIndex ) ? "add" : "remove"]( "selected" );
        if ( this.m_sCardNames )
        {
          oPage.getControlByName( this.m_sCardNames ).setDisplay( i == iCardIndex );
        }
      }
      oPage.getControlByName("stationview").setDisplay(false);
    }   
...

The output in the console is:

rsCommon.hackUnlockGlass                                                         rsCommon.js:146:4
_H6E._GU3:rns1:wait                                                                   _ZPI.js:6:1599
                                                                                                     MenuBar.js:118:7
0                                                                                                   MenuBar.js:121:9
overview                                                                                       MenuBar.js:122:9
1                                                                                                   MenuBar.js:121:9
stationview                                                                                   MenuBar.js:122:9
2                                                                                                   MenuBar.js:121:9
unitview                                                                                        MenuBar.js:122:9
3                                                                                                   MenuBar.js:121:9
trendview                                                                                     MenuBar.js:122:9
rsContentView._iframe_onerror().                                                rsContentView.js:737:4
rsCommon.hackUnlockGlass                                                         rsCommon.js:146:4
TypeError: oPage.getControlByName(...) is null[Learn More]       MenuBar.js:126:11
_4EJ._71
Title: Re: Custom control - Javascript error with getControlByName() - SOLVED
Post by: Blue on 07 Nov 2016 07:06:58 PM
OK, so no one replied.  Fine, I'll reply to myself :)

Went back to an older version of the report an added - tested change change in sequence.  A lot of changes and took a while.

There was NOTHING wrong with the JavaScript.

The error message, which indicated it came from the JS code, was actually triggered by a List object in the report.  The particular combination of this List object and a certain query caused the error.  Remove the list - no error, use a different query with the list - no error.

I made sure Report options didn't preserve any unused objects, deleted both List and query, saved the report, closed and opened it for edit again, created the query from scratch, added the list and associated the query with it, ran the report with EXACTLY the same JavaScript, and .....

NO ERROR!  Thanks IBM for 3 days of frustration.

So, thanks Blue for the response  ;D