Saturday 22 October 2011

IBM Cognos and JavaScript – Part I

Hi Guys

Nice article on Using Java scripts in Cognos 10

Ironside group , Java scripts


1) Get all the available tables on the page

a =document.getelementbytagname('Table')

2)Once you have all the tables try to get your table

b =a.items(1) -------- considering yours is the first table

3) once you get your table you can play with its properties like

b.classname

b.rows(0).cells(0)

b.title

 Below is a sample code

 <script language="javascript" type="text/javascript">

document.write("Hello World!");

var tbls = document.getElementsByTagName("TABLE");

var tblCnt = tbls.length;    

 for(var t=0; t<tblCnt; t++)

{

var tbl = tbls.item(t);        

if (tbl.className == "ls")

{

var cell= tbl.rows(0).cells(0); // reach the first cell of the first row of the list table

alert( cell.firstChild.innerHTML); //display the first cell content/text

}

}

</script>

Below is the script to add new option into a Prompt 


var myselect=document.getElementById("sample")

myselect.options[0]=new Option("New 1st option", "who") //replace 1st option with a new one

myselect.options[myselect.length]=new Option("Brand new option", "what") //add a new option to the end of



How to Debug ERRORS


basic idea to debug it write your output from each step that way you can debug ;

<script language="javascript" type="text/javascript">

var txt="Hello World!";

var a =txt.length;

document.write(txt.length);

</script>

What are Objects 


There are objects in java script like txt , date etc and there are methods to these objects like to uppercase to lowercase etc


Below are the methods available with string object

txt.big()

txt.small

txt.bold()

txt.fontcolor(green)

txt.fontsize(6)

txt.link("www.google.com")

txt.blink()

txt.touppercase()

txt.tolowercase()

write(str.search(/w3schools/i));--- performs case insensitive search

var str="Hello world!";

document.write(str.match(/WORLD/ i);

How to create Drop down list in Cognos


<script language="javascript" type="text/javascript">

function alertselected(selectobj)
{

 alert(selectobj.selectedIndex)

}

</script>


<form id="someform">

<select id="sample" onChange="alertselected(this)">

<option>Option 1</option>

<option>Option 2</option>

<option>Option 3</option>

</select>

</form>



Below is script to remove the parameter name

 <script language ="Javascript" Type ="Text/Javascript">

var fw = getFormWarpRequest();

var dropdown=fw._oLstChoicesyearprompt;

dropdown.remove(0);

dropdown.remove(0);

</script>

 ------------







No comments:

Post a Comment