0

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

null
    • Fred
    • 1 yr ago
    • Reported - view

    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.

      • thomas.4
      • 1 yr ago
      • Reported - view

      Fred Hi Fred! Thanks for your kind reply.

      I've tried what you said but I have always the same result

      This one was invalid:

      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" then 1 else x end
      

       

      so I tried to replace "undefined" with "0"

      let x := extractx(Titel, "-[^0-9]*(\d+)[^1-9]*(\d+,?\d*)x[^1-9]*(\d+,?\d*)cm-[^1-9]+(\d+)-?(\d+)?", "", "$5 ");
      if x := "0" then "1" else x end
      

      Here I've got result 0 also where I had a value. =/

    • Fred
    • 1 yr ago
    • Reported - view

    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.4
      • 1 yr ago
      • Reported - view

      Fred Thank! I've tried this too but I have as result "0" and not "1.  Also if there is s value for $5  

    • Fred
    • 1 yr ago
    • Reported - view
    thomas said:
    Thank! I've tried this too but I have as result "0" and not "1.  Also if there is s value for $5  

     Can 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.

    • Alain_Fontaine
    • 1 yr ago
    • Reported - view

    You could try:

    if trim(x) = "undefined" then…

    P.S. "debugValueInfo()" is your friend.

      • Fred
      • 1 yr ago
      • Reported - view

      Yes, I always forget debugValueInfo. One day it will stick in my head.

      • thomas.4
      • 1 yr ago
      • Reported - view

      Alain Fontaine this works!!! Thank you a lot for your help!!!

    • Ninox developper
    • Jacques_TUR
    • 1 yr ago
    • Reported - view

     

    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;
      • thomas.4
      • 1 yr ago
      • Reported - view

      Jacques TUR Fred Hi to everyone,

      thanks for your help! I've applied all your formula but I have always UNDEFINED as result if there is no value $5.

       

      The last one I've tried is this one:

       

      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;
      

      I've applied the formula on the field "Stück"

      This is the result: ( don't look at the field FORMULA on the bottom. It's just another test)

    • thomas.4
    • 1 yr ago
    • Reported - view

    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
  • 123Views
  • 4 Following