COGNOiSe.com - The IBM Cognos Community

IBM Cognos Analytics Platform => Cognos Analytics => Reporting => Topic started by: patton on 09 Sep 2017 07:45:09 AM

Title: Custom Control to set a prompt
Post by: patton on 09 Sep 2017 07:45:09 AM
HI all,

I have a custom control that shows a map and draws points corresponding to the data. When the user clicks the point, a popup shows up with some info. Now  I want to have a list beside a map and when the user clicks on the point, it should pass the value of the clicked point to filter the list.

I've created a filter on the list query with a prompt paramater ?pValue?. Is it possible to get the value from the custom control to populate a Cognos text prompt (using the setValue  or addValue control)?

Thanks in advance.
Title: Re: Custom Control to set a prompt
Post by: CognosPaul on 10 Sep 2017 07:58:51 PM
It should just be a matter of using the prompt API. Check out my post on the pmsquare blog: http://www.pmsquare.com/main/blog/cognos-analytics-custom-javascript-date-prompts-datasets/

If you post your control I can give you more specific advise.
Title: Re: Custom Control to set a prompt
Post by: patton on 18 Sep 2017 09:13:19 AM
Sorry for the late reply. I've create a value prompt named "ListBox1" with Autosubmit = Yes and parameter ?pParam?. ?pParam? filters a query.

here are some excerpts of my code

I'm also using Mapbox for displaying a map and points on it from Cognos query. There is code that displays a popup on the dot.

map.on('click', function(e) {
...nonimportant code...
   var feature = features[0];  --retrieves cognos data goten from oDataStore
paramValue = feature.properties.code; --sets the customercode that was clicked (or I hope so :) ) . te variable paramValue is declared at the start
  var popup = new mapboxgl.Popup({ offset: [0, -15] }) --sets the popup...
         .addTo(map)
   .this.f_onSetValuesClick.bind( this, oControlHost ); --calls the function

BasicControl.prototype.f_onSetValuesClick = function( oControlHost )
{
   var oControl = oControlHost.page.getControlByName( "ListBox1" );
   var oValues = paramValue --should contain the customer code that was clicked on the map.
   
      if ( oValues && oValues[0] )
   {
      oControl.setValues( [oValues[0]] );
   }

Title: Re: Custom Control to set a prompt
Post by: CognosPaul on 18 Sep 2017 04:42:39 PM
Splitting out the prompt API bit doesn't make much sense to me here.

   .this.f_onSetValuesClick.bind( this, oControlHost ); --calls the function

It looks like you're chaining that onto the popup. Is that intentional?

paramValue there looks like it's going to return a static number, something like 123. The prompt expects a specific object. So before we make any other drastic changes, try changing:
      oControl.setValues( [oValues[0]] );
to
      oControl.setValues( [{'use':oValues[0]}] );
Title: Re: Custom Control to set a prompt
Post by: patton on 19 Sep 2017 04:12:05 AM
I've thinked of a different approach. I let the map.onclick set the paramValue with the customer code (which it does, I've checked the console log)

Now, is there a way that when the global paramValue is changed, to fire the setValues? I've created a function from Cognos PromptButton examples.

BasicControl.prototype.f_onSetValuesClick = function( oControlHost)
{
   oControlHost.valueChanged();
   var oControl = oControlHost.page.getControlByName( "ListBox1" );
   var oValues = paramValue
   
      if ( oValues && oValues[0] )
   {
        oControl.setValues( [{'use':oValues[0]}] );
   }
};


Will this set the valueprompt and autosubmit the page in Cognos?


Title: Re: Custom Control to set a prompt
Post by: patton on 19 Sep 2017 07:55:52 AM
UPDATE:

I was able to addValues to a text box prompt with this function.

BasicControl.prototype.f_onSetValuesClick = function( oControlHost)
{
   console.log('pokrenuto')
   var oControl = oControlHost.page.getControlByName( "ListBox1" );
   var oValues = paramValue

      if ( oValues && oValues[0] )
   {    oControl.clearValues();
        oControl.addValues(  [{'use': oValues, 'display': oValues}]);
      
        oControlHost.reprompt();
        console.log(oValues + 'set')
   }
   
};


When I click a point on the map with customer code e.g. "123456", the text box prompt is filled with "123456" as expected. The report then refreshes, but nothing is filtered and the textbox prompt is empty. I've tried setting oControlHost.reprompt() , oControlHost.finish() and oControlHost.next() , but they all behave the same.

Is there a way to set a parameter any other way?

EDIT: I've came across an unusual behavior. When clicked on the point, the text box prompt is filled with customer code. I've remove the ControlHost.reprompt(); part from the code, and created a simple reprompt button. Now when I click the point, it fills the text box prompt and if press the reprompt button on my report, it doesn't accept the value.

BUUUUT, if i first click on the text box prompt with a value inside it , press enter and then hit reprompt, voila, it reprompts and filters the query. Is there a way to force the text box prompt to pass the paramater?
Title: Re: Custom Control to set a prompt
Post by: CognosPaul on 19 Sep 2017 10:35:50 AM
I've come across some cases where using setValues or addValues sets the prompt correctly, but it doesn't catch it. I believe it's a bug that is due to be fixed at some point. Which version are you using?

In the meantime you can probably get around it by triggering the onChange event on the element. I *think* you can get the element by using oControl.element. Then do oControl.element.onChange().
Title: Re: Custom Control to set a prompt
Post by: patton on 21 Sep 2017 09:03:48 AM
I've tried putting the valueChanged(), but no luck. When I switched to a value prompt, it worked like a charm.
Title: Re: Custom Control to set a prompt
Post by: anandcognos on 08 Aug 2018 01:26:29 PM
{
   
        var ControlprogramVPFinance = oControlHost.page.getControlByName("programVPFinance");
       
ControlprogramVPFinance.on('change', function(e) {
       
          this.f_onChange.bind( this, oControlHost );

        });

f_onChange is name of fucntion that I want to call. I set the UI type property of custom control to UI with event propagation.
I request you to please guide me. Thanks.
Title: Re: Custom Control to set a prompt
Post by: CognosPaul on 14 Aug 2018 10:27:15 PM
Is your control actually drawing something on the page? If not, set the UI type to none.