Column Expressions - write a value if cell is not empty

Dear KNIMErs,

I am currently struggling with what I assume is an error in my JavaScript code in the Column Expressions Node.

This is my table:

I have a table that comes prefilled in certain rows from some upstream nodes, see screenshot below. Basically what I want to do is to check for the winning supplier (stored in a flow variable) and if the winning supplier is ABC and the cell so far is empty, then assign the value from the original column.

Here’s the table I start with:
image

And this is the JavaScript code, I have used in the Column Expressions Node:

if (column("assigned volume") !== "") {
    column("assigned volume")
} else if (variable("var-winning-vendor") == "ABC" && isMissing(column("assigned volume"))) {
    column("original value")
}

Basically I want the 90,000 from vendor DEF to be copied and pasted in the assigned volume column for Row2 and the 130,000 from vendor DEF for Row3.

As I am not very well versed in JavaScript, I think my “formula” is somehow wrong, but I couldn’t find a place to correct it.

Here’s the workflow (KNIME Hub):
example-for-column-expressions – KNIME Community Hub

Thank you in advance…
Phil

Hi @kowisoft :wave: ,

If I have understood your issue correctly, I think it is enough to make a slight change in the expression to produce the expected result:

if (not(isMissing(column("assigned volume")))) {
    column("assigned volume")
} else if (variable("var-winning-vendor") == "ABC" && isMissing(column("assigned volume"))) {
    column("original value")
}

Your first IF was not working because your logic was: “IF not an empty cell then”; instead, you need “IF not a missing cell then”.

I am also attaching the workflow to this thread.:knime:

I hope it could be helpful, BR.
example-for-column-expressions.knwf (9.7 KB)

4 Likes

Thank you @diego

I wonder if the negation of the isMissing works because it is basically built in with Column Expressions Node? Would the code have worked, if the cell in fact would have been an empty cell (instead of a missing one)?

You need to include isMissing OR ==“” to cover both, or just clean it up prior with Missing Values.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.