+ All Categories
Home > Documents > Cognos Prompt API At CU - IBM Cognos User Group · PDF fileCognos Prompt API At CU Carl...

Cognos Prompt API At CU - IBM Cognos User Group · PDF fileCognos Prompt API At CU Carl...

Date post: 06-Mar-2018
Category:
Upload: truongkhuong
View: 238 times
Download: 5 times
Share this document with a friend
24
Cognos Prompt API At CU Carl Sorenson Associate Director of Reporting Systems University of Colorado Office of University Controller Friday, 24-Jan-2014 Rocky Mountain Cognos User Group
Transcript

Cognos Prompt API At CU

Carl Sorenson Associate Director of Reporting Systems

University of Colorado Office of University Controller

Friday, 24-Jan-2014

Rocky Mountain Cognos User Group

This is just showing what we’ve been able to do with the API so far. I will give you some helpful clips of

code. Do not ask for me to send you our slick Javascript library that you can plop in to your

reports. We don’t have one. We just code what we need into each report.

Carl Sorenson University of Colorado, OUC

Rocky Mountain Cognos User Group 24-Jan-2014

Cognos Prompt API first available in Cognos 10.2

Carl Sorenson University of Colorado, OUC

Rocky Mountain Cognos User Group 24-Jan-2014

Regular expression validation

Carl Sorenson University of Colorado, OUC

Rocky Mountain Cognos User Group 24-Jan-2014

The Finish button is grey and a message next to it tells the user what is wrong.

Regular expression validation

Carl Sorenson University of Colorado, OUC

Rocky Mountain Cognos User Group 24-Jan-2014

The instant the user manages to get in a legit looking code, the Finish button activates and the message is gone.

Regular expression validation

Carl Sorenson University of Colorado, OUC

Rocky Mountain Cognos User Group 24-Jan-2014

Why not just have the explanation text simply there all the time, next to the Input box? Because this would clutter up our pages with quite a bit of text telling what is really totally beginner stuff that our typical user knows.

Regular expression validation

Carl Sorenson University of Colorado, OUC

Rocky Mountain Cognos User Group 24-Jan-2014

Regular expression validation

Carl Sorenson University of Colorado, OUC

Rocky Mountain Cognos User Group 24-Jan-2014

Regular expression validation

Carl Sorenson University of Colorado, OUC

Rocky Mountain Cognos User Group 24-Jan-2014

<script> var oCR=cognos.Report.getReport("_THIS_"); // GET COGNOS PROMPT OBJECTS … ORG_PROMPT=oCR.prompt.getControlByName("ORG"); … // GET TALK-BACKS // TB means "talk back" to the user. // These initializations ensure that the talk-backs work in Firefox when rerunning. With out these, in Firefox the talk-backs work on the initial run only. … if (ORG_TB.innerHTML != 'org tb'){ORG_TB=document.getElementById("ORG_TB");} … // INPUT VALIDATION … ORG_PROMPT.setValidator(function(values){ if (values.length==0 || values[0].use.match(/^([BCDHSU1-9]\d{4}|ALLCU)$/)) {ORG_TB.innerHTML="";return true;} else {ORG_TB.innerHTML="<img src='/crn/prompting/reportskin/prompting/images/error_timed_small.gif'></img>The ORG | ORGNODE prompt requires five characters. The first can be a capital B,C,D,H,S,U or a non-zero digit. The rest must be digit. ALLCU is also accepted.";return false;} });

Regular expression validation

Carl Sorenson University of Colorado, OUC

Rocky Mountain Cognos User Group 24-Jan-2014

… // INPUT VALIDATION … ORG_PROMPT.setValidator(function(values){

if (values.length==0 || values[0].use.match(/^([BCDHSU1-9]\d{4}|ALLCU)$/)) {ORG_TB.innerHTML="";return true;}

else {ORG_TB.innerHTML="<img src='/crn/prompting/reportskin/prompting/images/error_timed_small.gif'></img>The ORG | ORGNODE prompt requires five characters. The first can be a capital B,C,D,H,S,U or a non-zero digit. The rest must be digit. ALLCU is also accepted.";return false;} });

values[0] because Cognos always returns an array, so we know for a text box just look in the first position which is indexed 0.

Values[0].use because Cognos always returns a use value and a display value, so we know for a text box all that really matters is the use value.

setValidator is the Cognos provided method for us to fill in with whatever Javascript we desire. (The term “method” is programmer jargon for a certain kind of function or subroutine.)

Regular expression validation

Carl Sorenson University of Colorado, OUC

Rocky Mountain Cognos User Group 24-Jan-2014

… // INPUT VALIDATION … ORG_PROMPT.setValidator(function(values){

if (values.length==0 || values[0].use.match(/^([BCDHSU1-9]\d{4}|ALLCU)$/)) {ORG_TB.innerHTML="";return true;}

else {ORG_TB.innerHTML="<img src='/crn/prompting/reportskin/prompting/images/error_timed_small.gif'></img>The ORG | ORGNODE prompt requires five characters. The first can be a capital B,C,D,H,S,U or a non-zero digit. The rest must be digit. ALLCU is also accepted.";return false;} });

The match method is built into Javascript. It’s not from the Cognos API. When the regular expression is going to be used in just one place in the code, I prefer match over the new RegExp object create you’ll see suggested in the Cognos API documentation.

Regular expression validation

Carl Sorenson University of Colorado, OUC

Rocky Mountain Cognos User Group 24-Jan-2014

… // INPUT VALIDATION … ORG_PROMPT.setValidator(function(values){

if (values.length==0 || values[0].use.match(/^([BCDHSU1-9]\d{4}|ALLCU)$/)) {ORG_TB.innerHTML="";return true;}

else {ORG_TB.innerHTML="<img src='/crn/prompting/reportskin/prompting/images/error_timed_small.gif'></img>The ORG | ORGNODE prompt requires five characters. The first can be a capital B,C,D,H,S,U or a non-zero digit. The rest must be digit. ALLCU is also accepted.";return false;} });

Regular expressions do require some study to learn. If you are a programmer I say learn them and use them. If it was really better to express everything “in plain english-like commands” we’d all still be programming in COBOL.

Regular expression validation

Carl Sorenson University of Colorado, OUC

Rocky Mountain Cognos User Group 24-Jan-2014

… // INPUT VALIDATION … ORG_PROMPT.setValidator(function(values){

if (values.length==0 || values[0].use.match(/^([BCDHSU1-9]\d{4}|ALLCU)$/)) {ORG_TB.innerHTML="";return true;}

else {ORG_TB.innerHTML="<img src='/crn/prompting/reportskin/prompting/images/error_timed_small.gif'></img>The ORG | ORGNODE prompt requires five characters. The first can be a capital B,C,D,H,S,U or a non-zero digit. The rest must be digit. ALLCU is also accepted.";return false;} });

Use Values.length==0 || for optional prompts because if the user clears the box Cognos returns a null array, which is length zero. Trying to look at the use value inside a null array would abend. Double bar is Javascript for “or”.

Group require

Carl Sorenson University of Colorado, OUC

Rocky Mountain Cognos User Group 24-Jan-2014

All of these prompts are set as optional. Yet the Finish button is not activated. It will not activate until the user fills in any one of a set of prompts that we define in the Javascript. We are preventing the user from running the report “wide open” which takes a long time and isn’t what they need.

Group require

Carl Sorenson University of Colorado, OUC

Rocky Mountain Cognos User Group 24-Jan-2014

Entering either a speedtype or an org |orgnode causes the Finish button to activate.

Group require

Carl Sorenson University of Colorado, OUC

Rocky Mountain Cognos User Group 24-Jan-2014

Group require

Carl Sorenson University of Colorado, OUC

Rocky Mountain Cognos User Group 24-Jan-2014

Actually, our group require set in this report is 1. Speedtype 2. Org | orgnode 3. Program 4. Project 5. Subclass You will see this in the Javascript code in the next few slides.

Group require

Carl Sorenson University of Colorado, OUC

Rocky Mountain Cognos User Group 24-Jan-2014

The trick to this is: 1. Put a setValidator on all 5 of the group required prompts, even on the select-

and-search prompt. It is not possible for the user to select an invalid code in this kind of prompt. Nevertheless we put a setValidator method on it anyway. We do this so we can make use of the event that fires when the user inserts a value.

2. Programmatically alter another hidden prompt that is a good old fashioned required prompt.

Group require

Carl Sorenson University of Colorado, OUC

Rocky Mountain Cognos User Group 24-Jan-2014

Group require

Carl Sorenson University of Colorado, OUC

Rocky Mountain Cognos User Group 24-Jan-2014

<script> var oCR=cognos.Report.getReport("_THIS_"); // GET COGNOS PROMPT OBJECTS … ORG_PROMPT=oCR.prompt.getControlByName("ORG");

PGM_PROMPT=oCR.prompt.getControlByName("PGM"); PROJ_PROMPT=oCR.prompt.getControlByName("PROJ"); SUBCLASS_PROMPT=oCR.prompt.getControlByName("SUBCLASS"); AWARD_PROMPT=oCR.prompt.getControlByName("AWARD"); SPDTYPE_PROMPT=oCR.prompt.getControlByName("SPDTYPE"); GROUP_REQUIRE_PROMPT=oCR.prompt.getControlByName("GROUP_REQUIRE"); … // INPUT VALIDATION

SPDTYPE_PROMPT.setValidator(function(values){ if (values.length==0 & ORG_PROMPT.getValues().length==0 & PGM_PROMPT.getValues().length==0 & PROJ_PROMPT.getValues().length==0 & SUBCLASS_PROMPT.getValues().length==0 & AWARD_PROMPT.getValues().length==0 ) {GROUP_REQUIRE_PROMPT.clearValues();} else {GROUP_REQUIRE_PROMPT.setValues([{'use':'YES'}]);} return true; }); …

Group require

Carl Sorenson University of Colorado, OUC

Rocky Mountain Cognos User Group 24-Jan-2014

… ORG_PROMPT.setValidator(function(values){

if (values.length==0 & SPDTYPE_PROMPT.getValues().length==0 & PGM_PROMPT.getValues().length==0 & PROJ_PROMPT.getValues().length==0 & SUBCLASS_PROMPT.getValues().length==0 & AWARD_PROMPT.getValues().length==0) {GROUP_REQUIRE_PROMPT.clearValues();} else {GROUP_REQUIRE_PROMPT.setValues([{'use':'YES'}]);} if (values.length==0 || values[0].use.match(/^([BCDHSU1-9]\d{4}|ALLCU)$/)) {ORG_TB.innerHTML="";return true;} else {ORG_TB.innerHTML="<img src='/crn/prompting/reportskin/prompting/images/error_timed_small.gif'></img>The ORG | ORGNODE prompt requires five characters. The first can be a capital B,C,D,H,S,U or a non-zero digit. The rest must be digit. ALLCU is also accepted.";return false;} });

clearValues and setValues are Cognos prompt API methods.

Prompt API Samples

Carl Sorenson University of Colorado, OUC

Rocky Mountain Cognos User Group 24-Jan-2014

There are some great sounding examples in the Cognos provided Prompt API Samples, such as: Personal default prompt selections - set selections This report allows the user to save a set of default prompt selections for use in subsequent reports. The prompt selections are saved to browser cookies for reuse in other reports. I have not studied these yet.

Debugging

Carl Sorenson University of Colorado, OUC

Rocky Mountain Cognos User Group 24-Jan-2014

If your first experience with Javascript is going to be with the Cognos API, it might be frustrating. Like most programming languages Javascript syntax is exacting. Javascript doesn’t give you much information about what is wrong when you make a mistake. Now embed this into something as complicated as Cognos and you’ve got your work cut out for you. Fortunately there are many books and web sites about Javascript. I simply code alert statements into places where I need to inspect a value and then later remove them.

Odd and Ends

Carl Sorenson University of Colorado, OUC

Rocky Mountain Cognos User Group 24-Jan-2014

If you use the Cognos API clearValues() method, you may need to follow it with a checkData() to get Cognos to completely reset the prompt. If you use the Cognos API getValues() method and there is a double-quote character in the data, the getValues() will fail. This is a bug we have reported to Cognos. If you call the Cognos API Report Action object’s FINISH, test that it works in a report view of your report. We found that it did not. I’ve had difficulty trying to use the API with in_range prompting. I am not sure if my problem is a bug or just a lack of understanding. If you use the Cognos API to set defaults these are ignored in scheduled runs and in drills. Javascript only runs when you actually visit the prompt page that it is embedded into.


Recommended