Home
Analytics
IF Statement
magic_bern
Hi All,
i have a table in which some meter names were not stored by the name the management would like to report it by. In my report, i am using th following if statement:
if (dataSetRow["metername"] == 'nhm_e_lthw') {
'QwCHPa1';
}
else if (dataSetRow["metername"] == 'nhm_e_ct') {
'QwCHPa2';
}
else if (dataSetRow["metername"] == 'nhm_ohc') {
'CHP Td Tn';
}
else if (dataSetRow["metername"] == 'nhm_aec') {
'ECHP d n';
}
else if (dataSetRow["metername"] == 'nhm_h1af52') {
'PECHP d n';
}
but for some reason the rows are not being displayed. the same thing happen when i use "" instead of '' on string. also, when i use the = instead of == it returns only the first if statement for everything.
I am using Birt 232. any help on the syntax of this if statement would be much appreciated
Thank you
Berny
Find more posts tagged with
Comments
thuston
That code should be fine (as long as you only have those 5 possible values).<br />
I think what you are asking is where the other values went.<br />
You need to add the default condition too.<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
...
}else{
dataSetRow["metername"];
}</pre>
<br />
You should not need the Java String.equals('value')<br />
It is Java/Javascript, so always use == for comparison. = is for assignment.<br />
<br />
The Switch is usually easier to read and maintain than a cascade of 'if else if'<br />
<a class='bbc_url' href='
http://www.w3schools.com/js/js_switch.asp'>http://www.w3schools.com/js/js_switch.asp</a>
;
magic_bern
Thanks Thuston for the reply,
my problem is not the default value and i only have those 5 metername in my result set.
actually when i add the default else value it just ignore everything and act as if there were no if statement
i do a similar thing with numbers and it works fine. it led me to think it had something to do with the data time and tried this BirtComp function but still no luck.
if ( BirtComp.equalTo ( dataSetRow["metername"] , "nhm_e_lthw" )){
"QwCHPa1";
}
else if (BirtComp.equalTo ( dataSetRow["metername"] , "nhm_e_ct")) {
"QwCHPa2";
}
else if ( BirtComp.equalTo ( dataSetRow["metername"] , "nhm_ohc") ){
"CHP Td + Tn";
}
else if ( BirtComp.equalTo ( dataSetRow["metername"] , "nhm_aec") ){
"ECHP d+n";
}
else if ( BirtComp.equalTo ( dataSetRow["metername"] , "nhm_h1af52")) {
"PECHP d+n";
}
I will try the switch to see if it works and let u know.
Regard
mwilliams
Where are you putting this script?
magic_bern
I am putting the script in the expression of a data item which i place in the detail row of the table
magic_bern
Hi All,
I finally got my IF statement to work using this:
if (dimension["Metername"]["metername"] == "NHM_E_LTHW") {
"QwCHPa1";
}
else if (dimension["Metername"]["metername"] == "NHM_E_CT") {
"QwCHPa2";
}
else if (dimension["Metername"]["metername"] == "NHM_AEC") {
"ECHP d+n";
}
else if (dimension["Metername"]["metername"] == "NHM_H1AF52") {
"PECHP d+n";
}
else if (dimension["Metername"]["metername"] == "NHM_OHC") {
"CHP d+n";
}
the main difference being the fact the metername to change are in capital letter, meaning that == assignment for string is case sensitive by default.
Thank you guys for your help