0

I would really appreciate some help with a computed column using an expression in Birt.

I have two columns which are giving results, one gives email addresses and one gives contact numbers: telephone, mobile..

When the email result is null then the contact number column shows a number, these are separate communication methods from a table in sql.

What I would like to do is create a new computed column for both the email address and the telephone number, when emailaddress is null then replace with contactnumber = contact and when contactnumber is null replace with emailaddress.

I've looked at a few similar questions online and found that entering the below script into the birt expression builder is accepted when you click validate, but it is not loading the report in the erp software I am using.

Is the expression itself correct?

if(row["destination"] == null){
row["contact"];
}
else if(row["contactnumber"] == null){
row["contact"];
}
else{
return true;
}

Kind regards,

Stuart

TheOx
  • 67
  • 7

3 Answers3

0

No, it is not correct (syntactically valid, though).

First of all what we've got here is an expression, not a function. So there shouldn't be a return statement.

And obviously true cannot be right. The other values are (probably) strings, so this should be a string as well.

I'm not quite sure what you actually want to achieve. Maybe you are looking for something like COALESCE in SQL oder NVL in Oracle SQL?

I suppose you create a JS function, test it with JSfiddle or so, then place it in the initialize script and call it in the expression.

hvb
  • 2,484
  • 1
  • 10
  • 13
  • I've had an answer through Eclipse forums, kudos to Jerry. This is an expression which works well, it leaves a blank space when there is a null value, then gives the next entry that has a value directly beneath. if(row["destination"] == null){ row["contactnumber"]; } else { row["destination"]; } – TheOx Sep 23 '21 at 09:05
  • Much simpler is: row["destination"] || row["contactnumber"] – hvb Sep 24 '21 at 14:40
0

By using the following in a Birt Expression, this replaces one column with another columns value if null.

if(row["destination"] == null){
row["contactnumber"];
} 
else { 
row["destination"]; }
TheOx
  • 67
  • 7
0

U may try this strange construction

if (!row["doc_no"] === false){
//if value is not null\NaN\empty\0
}
Sergey
  • 1