expression node syyntax issue

Hi, Just a simple one. I have tried to use KAI to check a syntax error in an IF Contains statement using the Expression Node. However back in Knime it still doesnt like it - Please can I check if i missed something below

if (contains(column(“Organisation”), “#”)) { column(“Siglum Level4”] } else { column(“Organisation”) }

Thanks

I could see that there is a Square bracket “]” instead of round bracket )" in above formula
Can you try this ?
if (contains(column(“Organisation”), “#”)) { column(“Siglum Level4”) } else { column(“Organisation”) }

Welcome Arun by the way.

Thanks . I missed that square brackets but even after changing it ( plus copying over your line ) the Expressions node is still showing syntax errors

I even checked again with KAI but no luck

Hey there,

general syntax I think you got right:

if() {
    
} else {
    
}

when I copy your example my Column Expressions does not seem to like your quotation marks.

When I build your logic into the above structure by clicking on the columns button etc I get this and it works:

if(contains(column("Organisation"),"#")) {
    column("Siglum Level4")
} else {
    column("Organisation")
}

1 Like

@MartinDDDD
Thanks Martin, That works in the legacy expressions node :slight_smile: I can use this node of course, Thanks.

I was trying to use the new Expressions node and the syntax in that node is different - $ instead of Column, [ instead of (
Using the “click” to choose columns etc but adding {} where it would be in the legacy version =

if (contains($[“Organisation”], “#”)) {
$[“Siglum Level4”] }
else {
$[“Organisation”] }

However in my Knime this gives a syntax error at the first { token recognition error at: ‘{’

Not sure if this again a non recognised key stroke or the inputs actually something other than {}

ahh - sorry I assumed you were using legacy, because your formula looked like JavaScript, which only works with legacy column expression.

In the new Expression Node this should work:

if(contains($["Organisation"],"#"),$["Siglum Level4"],$["Organisation"])

I followed the examples you get, when you highlight a formula in the right box:

2 Likes

Thanks Martin, I was missing the comma instead of the ELSE .

1 Like

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