If you are unable to create a new account, please email support@bspsoftware.com

 

Attempting to auto-submit a hidden prompt page with Custom Control Javascript

Started by ThatKingslayer, 18 Apr 2019 07:59:02 AM

Previous topic - Next topic

ThatKingslayer

Hey everyone! Long time lurker, first time poster, and all of that jazz.

I am attempting to use Custom Control Javascript in an Interactive Report to auto-submit a hidden prompt page. I obtained a piece of Javascript from a post on this site (If I could remember the username, I'd give them props) and tried it out but I feel like I am missing something. I've included the JS file at the bottom of this message. For the sake of providing screenshots, I have removed the piece of code that hides the prompt page just so the values can be seen. I've tried to include several screenshots as well.

I have a prompt page

with two Value Prompts that are being populated with default values by using a query that calculates the end of the previous month and a default category called View (this one is not giving me troubles). The idea is that the report will run, the query will execute and populate the value prompts, the two associated parameters (PeriodEndDate and View) will now have a value in them, and then the main report will receive those once the auto-submit has taken place.

The problem is that the value Prompt that receives the End of the month value from the query and populates the PeriodEndDate parameter is not doing that. As a test, I updated the prompt page to display the value of the PeriodEndDate parameter. At run time and before the Auto-submit timer runs out, there is not a value for the parameter -


Once the page auto-submits, it takes me to a prompt page to provide a value for the parameter PeriodEndDate even though the value prompt SHOULD have received this from the query.


Is there anything in the Javascript that needs to be updated in order to populate the value prompt so that the PeriodEndDate parameter has its value?

As promised, here is the JS that I found on Cognoise. Thanks in advance everyone!

define( function() {
"use strict";

document.head.appendChild( document.createElement( "STYLE" ) ).innerHTML =
"TABLE.clsViewerProgress," +
"TABLE.clsViewerProgress *" +
"{" +
"visibility: hidden !important;" +
"}";

function Control()
{
};

Control.prototype.show = function( oControlHost )
{
var fDefaultSeconds = 0.05;
var fSeconds = ( oControlHost.configuration ? oControlHost.configuration.Seconds : fDefaultSeconds ) || fDefaultSeconds;
this.m_iTimer = setTimeout( oControlHost.finish.bind( oControlHost ), Math.round( fSeconds * 1000 ) );
};

Control.prototype.hide = function( oControlHost )
{
this.cancelRefreshTimer();
};

Control.prototype.destroy = function( oControlHost )
{
this.cancelRefreshTimer();
};

Control.prototype.getParameters = function( oControlHost )
{
// WARNING: Do not remove this method.
// Pages that don't contain prompt controls are cached by the viewer. The existence of a getParameters
// is used as the indicator that the custom control is prompt-like and will prevent caching.
};

Control.prototype.cancelRefreshTimer = function()
{
if ( this.m_iTimer )
{
clearTimeout( this.m_iTimer );
this.m_iTimer = null;
}
};

return Control;
});

dougp

This type of question comes up so much I'll just give up and share all my work on the subject:

https://github.com/dougpulse/Cognos

It includes JavaScript modules for Cognos Analytics, sample reports to demonstrate how to use the JavaScript features, as well as some sample reports demonstrating how to take advantage of specific Cognos features.


ThatKingslayer

That sounds amazing, Doug. Thank you so much!

I am extremely new to Javascript so I apologize for asking something that is a frequent flyer. I searched the boards for quite some time before taking the time to make my post and didn't immediately see something that had my answer, however, I am also so unfamiliar with Javascript that I possibly came across the answer without realizing it.

ThatKingslayer

I wanted to follow-up by saying that I was able to figure out what was happening. I thought I would share my solution in case someone comes across this in the future. I'll also note for future searchers that this is an Interactive Cognos 11+ report that is using Custom Control javascript.

Because of my extreme lack of knowledge in the world of Javascript, I was focusing entirely on the wrong thing with my original post. The auto-submit functionality was working perfectly. The issue was that the value that I needed from my value prompt was not being set properly so once the page auto-submitted, my date parameter did not have the value in it from the value prompt.

To make this work, I wrote a very short piece of Javascript to grab third value in the Value Prompt. If it were a different type of prompt, you may need to grab the first or second value instead. Luckily, you can easily modify the JS file to suit your needs by changing the number in the oValues[] to 0, 1, 2, etc. Because I want the third value, mine is set to 2.

Here is the code:
define( function() {
"use strict";

document.head.appendChild( document.createElement( "STYLE" ) ).innerHTML =
"TABLE.clsViewerProgress," +
"TABLE.clsViewerProgress *" +
"{" +
"visibility: hidden !important;" +
"}";

function Control()
{
};

Control.prototype.show = function( oControlHost )
{
/* Prompt Control Configuration within the Cognos Report - "name": "ValuePrompt1"
Returns the Third Value in the prompt. The "First" value is 0 which is why you see a 2 below.
This is mostly used with a dropdown value prompt where the third value is the one needed.  */

this.m_sName = oControlHost.configuration.name || "ValuePrompt1";
var oControl = oControlHost.page.getControlByName( this.m_sName );
var oValues = oControl.getValues(true);
if ( oValues && oValues[2] )
{
oControl.setValues( [oValues[2]] );
}
};

return Control;
});


rodrigo79rph

Hi ThatKingslayer,

Thanks for sharing how did you solve the issue to setup the default value. May I asked you how do you avoid the prompt page to re-submit every specific # of seconds?

rodrigo79rph

I noticed that the auto-submit doesn't keep submitting every # of seconds forever when used in the prompt page, only on regular report pages. Also I found there is another way to just set the default prompt value without running the auto-refresh code, but instead using the .next() function, again this only works within a prompt page, in regular report pages it gets in an infinite loop:

   this.m_sName = oControlHost.configuration.name || "ListBox1";
    var oControl = oControlHost.page.getControlByName( this.m_sName );
    var oValues = oControl.getValues(true);
   if ( oValues && oValues[0] )
   {
        oControl.setValues( [oValues[0]] );
       
   }
    oControlHost.valueChanged();
    oControlHost.next();

jems2021

Quote from: dougp on 18 Apr 2019 10:25:59 AM
This type of question comes up so much I'll just give up and share all my work on the subject:

https://github.com/dougpulse/Cognos

It includes JavaScript modules for Cognos Analytics, sample reports to demonstrate how to use the JavaScript features, as well as some sample reports demonstrating how to take advantage of specific Cognos features.

Dough, What if I have questions in regard to the JavaScript modules... How can we post the question?

dougp

So I see you posted an issue.  Unfortunately, the email account I have associated with github is currently broken.  I'll get back to you through github when I can.  It looks like I need to document a bit of my architecture.  Yours will be different and you'll need to adjust the code to meet your needs.