简体   繁体   中英

How to replace a column result if null with another column result in BIRT

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

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.

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"]; }

U may try this strange construction

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM