Show "1" instead UNDEFINED
Good morning everyone,
I am writing because I need "Field1" to show the result "1" when the result of the formula is "undefined". Otherwise it must show the correct number, extracted by the formula.
extractx(Titel, "-[^0-9]*(\d+)[^1-9]*(\d+,?\d*)x[^1-9]*(\d+,?\d*)cm-[^1-9]+(\d+)-?(\d+)?", "", "$5 ")
In some cases, the value "$5" is not present in the title of the file and consequently it says "undefined"
Alternatively it can also be hidden if the result is "undefined" but it would be better if it shows "1"
You can help me? Thank you
11 replies
-
You can try something like:
let x := extractx....; if x = "undefined" then 1 else x end
I’m not sure “undefined” is what Ninox sees or just what Ninox shows. You can try null as well.
-
Please make the following change:
if x = "undefined" then "1" else x end
I forgot that extractx results is a string so you have to put " " around 1 so the result is also a string. If you mouse over the red line number, see pic below, the error message will say what the problem is.
If you need the result to be a number you can always put the number command in front of line 2:
number(if x = "undefined" then "1" else x end)
-
thomas said:
Thank! I've tried this too but I have as result "0" and not "1. Also if there is s value for $5Can you check the code again? I looked at my example and typed the wrong code. It should be:
if x = "undefined" then "1" else x end
This is my full code that works by itself:
let x := extractx("NAME-Nr001-200x400cm-Backlight-2021", "(\d+).(\d+).(\d+)", "", "$7"); number(if x = "undefined" then "1" else x end)
If you still can't get it to work please post your full code and a sample of your data, so I can try it on my end.
-
You could try:
if trim(x) = "undefined" then…
P.S. "debugValueInfo()" is your friend.
-
There are two different cases:
1 - the required groups ($1, $ 2 and $3) were not found because the string does not contain the corresponding structure elements. extractx then returns null.
2 - the required groups were found, but the optional group requested ($4 or $5) was not found in the chain. In this case extractx returns "undefined".
The best thing to do is to test both possibilities:
let x := extractx(Titel, "-[^0-9]*(\d+)[^1-9]*(\d+,?\d*)x[^1-9]*(\d+,?\d*)cm-[^1-9]+(\d+)-?(\d+)?", "", "$5 ") if x = "undefined" or x = null then "1" else x end;
-
Have to tell you thatAlain Fontaine get the right formula.
This formula worked in this case:
let x := extractx(Titel, "-[^0-9]*(\d+)[^1-9]*(\d+,?\d*)x[^1-9]*(\d+,?\d*)cm-[^1-9]+(\d+)-?(\d+)?", "", "$5 "); if trim(x) = "undefined" or x = null then "1" else x end
Thank to all of you for your help!
Content aside
- Status Answered
- 1 yr agoLast active
- 11Replies
- 131Views
-
4
Following