To Prevent Auto Submit from generating the report in Cognos - cognos

I have 3 prompts. 1st Prompt contains the values A & B. On selecting A the remaining 2 prompts should get hidden and upon selecting B the 2 prompts should show. All the 3 prompts are mandatory. Can anyone help me achieve this scenario?

I'm going to assume that you already know how to conditionally hide and unhide elements and that you just want to know how to refresh a page without submitting it.
There are three solutions to your problem:
Add a reprompt button
Use JavaScript to detect when the radio button has changed state and reprompt the page
Use a workaround that uses a hidden value prompt
Method 1 - Reprompt Button
This is done by simply adding a prompt button to the report and setting the 'Type' property to 'Reprompt'. I don't recommend you use this method as requiring the user to click a reprompt button each time they change a prompt value is bad user experience.
Method 2 - JavaScript API
This method uses the Cognos-supported JavaScript API to reprompt the page whenever a value prompt changes value. Note that the API is only available in version 10.2 and later.
Name your value prompt. This is specified in the prompts 'Name' property. For the purposes of this tutorial, I'm going to use the name 'valuePrompt'.
Add an 'HTML Item' to the report.
Open the HTML item and paste in the following code:
<script>
var report = cognos.Report.getReport('_THIS_');
var valuePrompt = report.prompt.getControlByName('valuePrompt');
var currentValues = (valuePrompt.getValues().length == 0) ? [{'use':''}] : valuePrompt.getValues();
valuePrompt.setValidator(validateValuePrompt);
function validateValuePrompt(values) {
if (values && values.length > 0) {
if (values[0].use != currentValues[0].use) {
currentValues = values;
report.sendRequest(cognos.Report.Action.REPROMPT);
}
} else {
currentValues = [{'use':''}];
}
return true;
}
</script>
The code is optimized so that the reprompt action only happens when the prompt is changed to a new value. This prevents multiple reprompts whenever the system checks the prompts for validity, which can happen quite often.
Method 3 - Hidden Dependent Prompt
This technique uses a hidden value prompt to trick Cognos into reprompting the page on every value prompt change by tying the prompt to a dummy value prompt using the cascading prompt functionality.
Add a new value prompt
Set the new prompt's 'Required' property to 'No'
Set the 'Cascade Source' property for the new prompt to be the parameter of the previously existing value prompt
Hide the new prompt
Set the 'Auto-Sumbit' property of your original value prompt to 'Yes'.
Whenever you change the value prompt, the page will reprompt in order to refresh the hidden prompt.

Related

How can I force read updates in all Smart Panel fields before reading it after a user updates and closes it?

I have a smart panel where I preset a default value for a field within it. If the user changes the value of that field, when the popup is closed, the value remains the old, preset value. I've had this happen in two separate instances: one regarding setting a time and one regarding selectors. The fields are set to commit changes = true. Is there any way to force the code to grab the new value set by the user instead of keeping the value set before displaying the smart panel popup?
Example:
Smart panel has a view called Option. OptionA will be set to something before the popup is executed. After the popup is closed by the user, even if the user changed the selector's value, the code will see the originally set value to OptionA set programmatically before the popup was executed.
Option.Current.AOption = 10;
if (Option.AskExt(true) == WebDialogResult.OK)
{
//This will display the original value
Document.Ask(Option.Current.OptionA, MessageButtons.OK)
}
Initial popup:
User changed:
Popup after closing and executing Document.Ask():

Cognos 10 Report Studio: On Page Prompts & Performance

I have a report page which displays a crosstab. This is filtered by 5 paramaters. These paramaters are submitted by the user through on page checkbox prompts.
The requirement is to return the data with all values in all paramaters selected on the first run. If I leave default selections blank this behaviour is achieved but all the checkboxes are unchecked which gives misleading feedback to the user.
As an alternative I've manually specified all the values in default selections. However, this has a performance impact.
Does anyone have any alternative suggestions?
I've been looking for a way to specifically link a reprompt button to a value list so only those paramaters are resubmitted (rather than the whole page) but haven't found anything yet.
Thanks in advance - even if the answer is 'no and this is a bad way to go about it'!
One option is to use JavaScript to check all of the checkboxes after the page is rendered with no filtering applied. To do this all filters have to be set to optional. The page is rendered with all data and unchecked checkboxes. The JavaScript fires and checks all checkboxes so that the state of the prompts matches the state of the data. This happens so fast the user likely won't know the boxes weren't checked initially. A reprompt button will, when clicked, enforce whatever choices the user makes after that.
Since version 10.2, Cognos has provided a fairly simple JavaScript API to allow for render-time manipulation of prompt controls. Hopefully, you are working with 10.2 or later otherwise the code provided will not work. Here is a bit of JavaScript code that will loop through all prompts and select all values within them:
var report = cognos.Report.getReport("_THIS_");
var prompts = report.prompt.getControls();
if (typeof firstrun == "undefined") {
var values;
for (var i=0;i<prompts.length;i++) {
values = prompts[i].getValues(true);
prompts[i].addValues(values);
}
var firstrun = false;
}
Notes:
All value prompts behave the same way regarding the 10.2+ JavaScript Prompt API. It doesn't matter whether you choose a drop-down, list, checkbox or radio button interface. The way we code for all of these variations is the same. The provided code would work just as well with a list as it would with checkboxes.
Make sure that you wrap your code in script tags and that the HTML Item object you place on your page to hold the code appears below all prompt controls. If it is placed elsewhere it will not be able to find the prompt controls as they will not have been rendered when the code executes.
The code assumes that the only prompts on the page are the checkboxes you want checked. If there are other prompts on the page then you will have to target individual prompts using the getControlByName() function provided in the API rather than looping through all prompts. More information on the Cognos JavaScript Prompt API can be found here.
The key bits of code here are the getValues() and addValues() Cognos JavaScript Prompt API functions. getValues(true) returns a JSON-formatted object representing all values, selected or not, from a value prompt. addValues(values) takes a JSON-formatted object representing the values to be selected and selects them. Thus, it's a matter of grabbing all values and then passing them in to be selected.
The reason for the if block is that we only want this code to run once at first page render. When the user first runs the report we want all checkboxes checked but after that we want the checkboxes to retain state. If we didn't use the if block the user's choices would be overwritten after a reprompt. For more information on this technique check out this tutorial on my blog: JavaScript: Running Code Only Once.
Addendum
If you don't want any filters to be applied when all boxes are checked in a section even after subsequent reprompts you can do so by tweaking your filter.
Assume that we are checking against a model based item [Item1]. We have a current filter of: [Item1] in ?parameter1?. We also have four checkboxes with values of 'Choice1','Choice2','Choice3', and 'Choice4'.
The following modified filter will only apply the checkboxes to the filter when all four aren't checked:
(
'Choice1' in ?parameter1?
AND
'Choice2' in ?parameter1?
AND
'Choice3' in ?parameter1?
AND
'Choice4' in ?parameter1?
)
OR
[Item1] in ?parameter1?
If all four checkboxes are checked then the first part of the OR is satisfied and all rows will be returned. It should be fast too because most languages, including iterations of SQL, will not test the second component of an OR if the first component is satisfied.

xpages: compute Confirm Action confirmation text does not work in XPiNC

I'm using Notes/Domino 8.5.3. I've added a button control to an xpage. The button uses a Confirm Action to display a client-side prompt to the user before continuing with the next action defined for the button. When I use static text for the Confirmation Text for the Confirm Action, the confirmation prompt is displayed. However, when I change the Confirmation Text to be computed, and retrieve the text from a profile document, the confirmation prompt it not displayed at all in XPiNC. The confirmation prompt with the computed confirmation text is displayed just fine in a browser. Is there a work-around for this issue with XPiNC?
Following is the code I'm using in the Confirm Action to get the text for the prompt:
var server = database.getServer();
var dbProfile:NotesDocument = database.getProfileDocument("DBProfile", "");
var msg = dbProfile.getItemValueString("ContactsInitUpdatePrompt");
return msg;
To further my comments, this is a work around I use the below code for an app that uses the bootstrap extension library on the web but uses basic functionality with xpinc.
If the values for xPinc are different you could make the confirm action different in the browser and in the client.
if (#ClientType()== "Notes")
{
<action>;
}
else{
<action>;
}
I think that profile documents are a bad idea in xPages though. Having to restart HTTP to get a new value ruins the point I think. Almost better to hard code values at that point. I think you can set application scope to handle the work of profile documents. But then application scope in xpinc is just on the current machine as the server is the client.

One or more of the required values are missing although all prompt values have been selected

In my COGNOS prompt page, I have a button 'Generate'. On click of it, I call the script:
function generateReport(format) {
if(!canSubmitPrompt())
return;
...
..
}
Now although all the 'Required' Prompts on the page have been selected, I still get the error : 'One or more of the required values are missing. Required values are needed to produce the report.'
I also checked that all the filters on the main query subject that uses the Prompts are Optional
There was a hidden block on the parameter page with some required parameters. That was the cause of the problem. The hidden block was removed and that solved it.
Thanks everyone for reading.

Refresh InfoPath field after code-based calculation

I have an InfoPath 2010 form that creates a new Sharepoint list item. The form has, in essence, one input field and one output field. If something gets entered in the input field then some calculation is performed and I want the result to show up in the output field.As the calculation is somewhat complicated I need to do it in code, not through rules.
private void CalculateOutput()
{
XPathNavigator main = MainDataSource.CreateNavigator();
XPathNavigator service = main.SelectSingleNode("my:meineFelder/my:serviceValue", NamespaceManager);
double serviceValue = service.ValueAsDouble;
double output = 3*serviceValue; // much abbreviated version
// output now has the correct value
XPathNavigator outputNav = main.SelectSingleNode("my:meineFelder/my:output", NamespaceManager);
//Remove the "nil" attribute (otherwise we get an error when the field is a double instead of a string)
if (outputNav.MoveToAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance")) outputNav.DeleteSelf();
outputNav.SetValue(output.ToString());
}
My problem is that everything works fine in the InfoPath preview but once I deploy the form and run it in the browser the output field does not get updated, i.e. I cannot see the result of my calculations.
I have tried .ReplaceSelf (with OuterXML), with zero result. I have also played with assigning the result to another field and thereby firing an "set field value" rule, also to no avail.
If I submit the form, the output value is saved OK but I'd really like the user to see the output field before submitting.
Any Ideas?
Thx a lot.
In case of browser enabled form, ensure that you have set the "Postback Setting" to refresh "Always"
To do this right Click on the control on which the postback is to be triggered. (in your case Service value). Go to Browser Forms tab and set the Postback Setting to Always.

Resources