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

 

News:

MetaManager - Administrative Tools for IBM Cognos
Pricing starting at $2,100
Download Now    Learn More

Main Menu

Controlling Prompts with JavaScript

Started by dougp, 13 Jul 2018 05:49:24 PM

Previous topic - Next topic

dougp

I want more control over my prompt pages.

For example, I want to set all of my prompts to "not required" and parameterized filters to "optional" because there is no one prompt that should be required.  However, I don't want to allow the user to download the internet.  They should have to use some prompts, just not specific ones.  Maybe I want them to filter the report by a city and a year, or maybe a country and a month.  If I require city, they can't see the whole country without selecting every city in that country.  Painful.

Or maybe I just want to always has my date prompt default to one week ago, or maybe the last work day before today.

I have much of my prompt script worked out, but here are a few items I'm having trouble with.


  • Identifying which button (cancel, back, next, reprompt, finish) the user clicked that caused the script to enter the PageModule.hide() method.
  • Making a prompt validation function to run as described in the documentation for the PromptControl.setValidator() method.

    • Date (and DateTime?) prompts don't appear to use validators at all.
    • If a textbox prompt is empty because the user just deleted the content, the validator doesn't run.

Does anyone else here have experience with this?  Do you have the same problem?  Are there other problems I haven't noticed yet?  Did you find workarounds?

dougp

#1
Still no love...

I have a page module that includes the code below.  There is no effect on the Finish button.

I know I'm not the only one with this need.  Has anyone else here solved this?  Is there a different approach that will work?

this.oConfig = {"RequiredPromptCount":3};

if (this.oConfig.RequiredPromptCount) {
// loop through the prompts on the page
// increment a counter if a prompt is populated
// When the counter equals RequiredPromptCount, we're done.  Enable the Finish button.
// If the counter never grows to RequiredPromptCount, disable the Finish button.
// This should probably occur within the prompt validator function for every prompt.
//log("RequiredPromptCount:  ", this.oConfig.RequiredPromptCount);
var rpc = this.oConfig.RequiredPromptCount;
var ap = oPage.getAllPromptControls();
ap.forEach(function(p) {
//log("RequiredPromptCount:  Prompt", p.name);
// When the page loads, each prompt gets a setValidator function created.
p.setValidator(function () {
// While the user is interacting with the report, this code runs...
//log(p.name, "");
var c = rpc;
var i = 0;
var a = oPage.getAllPromptControls();
a.forEach(function(e) {
//log("    Prompt Validation:  Prompt" + e.name, JSON.stringify(e.getValues()));
//log("    Prompt Validation:  Prompt" + e.name, e.getValues()[0].use == undefined);
i += e.getValues()[0].use == undefined || e.getValues()[0].use == "" ? 0 : 1;
//log("    Prompt Validation:  Prompt" + e.name, i);
});
//log("PromptCount", i);
//log("RequiredPromptCount", c);
log("Valid Prompt", i >= c);
// ...but whether the function returns true or false has no effect on the Finish button.
return i >= c;
});
});
}

dougp

I worked this out in two different ways:

1.  Apparently I had solved this problem a while back, but forgot how I did it.  There's a file in my script library named PromptButton.js.  This includes code that does not allow the "Finish" action to take place without using the button, so it should work with auto-submit prompt controls that are intended to populate downstream prompts on the same page.  If auto-submit is intended to run the "Finish" action, that may not work.  It's also a little more flexible than (2), but that can easily be fixed.

2.  I created a new script based on something that I documented that I found here, but clearly, that's not the correct post.  (Maybe some Cognoise topic IDs got shuffled by a system restore?)  This one makes no accommodation for behavior when the auto-submit property is set.  This one currently only performs the "Finish" action, but could be enhanced to allow any action.  It is now in my library as PromptFinish.js.

Either one of these appear to meet my current need.  If you want to use these scripts, please keep in mind that extensive testing was not performed.  I don't know what they may do in a context other than where I am using them.