SpotOn Systems Blog by the Cognos Integration Experts!

Subscribe by Email

Your email:

Archived Blogs

Access archived "Where in my Cognos" and "Advanced Charting" blog posts. These posts are also available in "SpotOn the Cognos Edge" blog.

Your SpotOn the IBM Cognos Edge

Current Articles | RSS Feed RSS Feed

Accessing Prompt Controls in Cognos 8.4 with Javascript

Posted by Darren Nelson on Wed, Apr 15, 2009
  
  
  

Hi All,

During a recent client engagement, we came across an issue that some of you may have encountered: trying to access prompt controls at runtime.

In the past a Report Studio author could write something like this:

var x = getFormWarpRequest();
var y = x.elements["my control name"];

Of course, this is no longer the case in Cognos 8.4. Instead, the prompt control IDs are system-generated and obfuscated at runtime. In order to access the prompt controls now, you have to first obtain the obfuscated value, and then locate the control.

I've written a piece of code that seems to let me find the prompt control. I hope it helps your efforts!

In brief:

var y = searchPrompts("My prompt name");

<SCRIPT> function searchPrompts(promptName) { var SpotOnTargetControl = G_PM_THIS_.getControlByName(promptName); var SpotOnPCType=SpotOnTargetControl._type_; var SpotOnPCID = SpotOnTargetControl._id_; var SpotOnPCPrefix = ""; switch(SpotOnPCType) { case "cognos.Prompt.Control.SelectValue": SpotOnPCPrefix="PRMT_SV_"; break; case "cognos.Prompt.Control.Text": SpotOnPCPrefix="PRMT_"; break; case "cognos.Prompt.Control.DateTime": SpotOnPCPrefix="PRMT_"; break; case "cognos.Prompt.Control.Date": SpotOnPCPrefix="PRMT_"; break; } var SpotOnFW = getFormWarpRequest(); var SpotOnEL = SpotOnPCPrefix+SpotOnPCID; var SpotOnTargetElement = document.getElementById(SpotOnEL); return SpotOnTargetElement; } </SCRIPT> <A onclick='searchPrompts("TEST_LIST")' href="#">Get List named:TEST_LIST</A><BR> <A onclick='searchPrompts("TEST_TEXT")' href="#">Get Text named:TEST_TEXT</A><BR> <A onclick='searchPrompts("TEST_CALENDAR")' href="#">Get CALENDAR named:TEST_CALENDAR</A>

Tags: , , , , ,

COMMENTS

This is kickass...thanks for the work...saved my day!

posted @ Monday, September 14, 2009 10:27 PM by HKM


Hi 
 
That was a gr8 post. 
 
I used your function like this and it doesn't show me the alert message. 
 
var y =searchPrompts("TEST_TEXT"); 
 
var z=y.value; 
 
alert(z); 
 
 
 
Where am I wrong? 
 

posted @ Friday, January 15, 2010 2:11 PM by Mark


Amazing! thanks a lot. You saved my day too.

posted @ Friday, February 19, 2010 5:36 PM by danman980


Using this I am not able to display the date selected in a date prompt. Any other code to perform this?

posted @ Tuesday, March 02, 2010 1:22 AM by smapy


Also, i would like to understand the whole concept of JavaScripts usage in Cognos 8.4. There are plenty of things that is available in our Cognos 8.1 and all shows a javascript error in Cognos 8.4. Please share any document that would be useful.

posted @ Tuesday, March 02, 2010 1:25 AM by smapy


Mark, 
 
 
 
Replace the line... 
 
var z=y.value;  
 
 
 
with ... 
 
var z=y.sGetValue();

posted @ Tuesday, March 23, 2010 7:14 PM by Charles


It works but when the report has a Tree Prompt the function G_PM_THIS_.getControlByName 
 
Returns an empty item. How do you recommend to solve this?

posted @ Friday, April 23, 2010 2:46 PM by Chris


Hi i am using a propmt function to check if the checkbox is selected in cognos 8.4. 
 
i am getting an error "cntlName.m_oForm.length" not defined. I am copying the script below can you please give the solution for it 
 
 
 
function checkGroupingLevel(){ 
 
for(i=0;i<oCVRS.preProcessControlArray.length;i++) 
 

 
cntlName=eval(oCVRS.preProcessControlArray[i]); 
 
if(cntlName.m_oSubmit.name.toLowerCase() == 'p_department') 
 

 
for(var j=0; j<cntlName.m_oForm.length; j++) 
 

 
if(cntlName.m_oForm[j].checked) 
 

 
document.formWarpRequest._oLstChoicesGroupingLevel[1].checked = true; 
 
 
 

 

 
break; 
 

 

 
promptButtonFinish(); 
 
 
 
 
 
 
 
}

posted @ Wednesday, June 09, 2010 8:41 AM by Praveen Paul


Once you get the object back, what do I do with it? I don't know what the properties or methods are for the object.

posted @ Monday, January 17, 2011 7:55 PM by BillyLone


Iam working on the audit page in cognos 8.2.I need to capture the filters/prompt used by the users.Iam running several reports.I need to capture prompts/filters used by each user.I have not done much on JS.Please let me know if you could help. 
 
 
 
Thanks in advance

posted @ Monday, March 14, 2011 9:35 AM by shyam


Hi, 
 
great post indeed, could it be that for text, date and datetime prompts the prefix is not complete? 
 
 
 
{  
 
case "cognos.Prompt.Control.SelectValue": SpotOnPCPrefix="PRMT_SV_";  
 
break;  
 
case "cognos.Prompt.Control.Text": SpotOnPCPrefix="PRMT_";  
 
break;  
 
case "cognos.Prompt.Control.DateTime": SpotOnPCPrefix="PRMT_";  
 
break;  
 
case "cognos.Prompt.Control.Date": SpotOnPCPrefix="PRMT_";  
 
break;  
 
}  
 
 
 
thanks! 
 
Dieter

posted @ Thursday, May 12, 2011 12:57 AM by Dieter


hi all, 
 
i need java script for prompt hide show at runtime in cognos 8.4. 
 
i have 3 prompts in prompmt page.. 
 
1.it is for selecting the year. 
 
2.this prompt having static choices i.e External report and Internal report. 
 
if user select External report dirictly list vl be dispalyed if user selecting the Internal 3rd promt must be enabeled the 3rd promt conatins 3 static choies .. 
 
so how to hide and show promt at selection of Internal.. 
 
help me on this issue 
 

posted @ Friday, August 05, 2011 2:20 AM by Daniel


Post Comment
Name
 *
Email
 *
Website (optional)
Comment
 *

Allowed tags: <a> link, <b> bold, <i> italics