String manipulation using "if" function

Dear friends,
Do you know what’s the bug as below? Knime pop up error message:

IF(column(“PNO digit”)=11,“00000”&column(“PNO”)&“00”,padleft(column(“PNO”),18,“0”))

Error Message:
Errors in code. Please fix the expression.
No function ‘padleft’ with 3 argument(s) defined. IF(column(“PNO digit”)=11,“00000”&column(“PNO”)&“00”,padleft(column(“PNO”),18,“0”)) ^ at line 1 at column 54

My original Excel expression is as below:

=IF(EM7=11,REPT(“0”,5)&G7&REPT(“0”,2),REPT(“0”,18-LEN(G7))&G7)

Hi @uix07344 , welcome to the KNIME community.

Firstly this isn’t a “bug”.

The specific problem referred to in the error message is that there is no such function in KNIME Column Expressions “padleft”. Column Expressions syntax is based on javascript and is case sensitive. The function is padLeft.

The more general problem is that you are trying to use a syntax that is not the syntax required by Column Expressions.

You need something more like this:

if (column("PNO digit")==11)
{
    "00000"+column("PNO")+"00"    
}
else
{
    padLeft(column("PNO"),18,"0")
}

You may find this link useful in a brief discussion of if else conditions in Column Expressions

3 Likes

Thank you so much! It works!

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