0

Stuck with custom function...

Hello,
I have a custom function to tweak a bit the contains() behaviour to use it together with a view field. 
My function is this: 

function containxORisORnull(Msource : text,Msearched : text,Moption : boolean) do
   if Msearched = null then
        true
   else
        if Moption = true then
            Msource = Msearched
        else
            testx(lower(Msource), lower(Msearched))
        end
    end
end;

 

When I search for something, it all works as expected:
(See the formulas for each field in the screenshot)

 My problem is that when the search bar is empty, the function works as expected in the formula field "test containxORisORnull" (returning true) but when I use it in the view field it DOESN'T display anything... :(

 Does someone know why? 😵

(In the view field, I tested writing select Asistentes where true and it selects my record... so I don't know why it doesn't when using the formula that is returning "true"...
Asistentes for now is another table where there's only one test record with Company Name = "aaaa")


Thank you!!!

4 replies

null
    • Elena_Rodriguez
    • 15 hrs ago
    • Reported - view

    My goal is to have a custom function, that I can use together with views.
    For each view I have a search bar.
    I want the view to display all records when I'm not searching anything and to display the matches only when I've typed something to the search bar. 

    I comment my own code to hopefully make my question less dense

    • Sviluppatore Ninox
    • Fabio
    • 15 hrs ago
    • Reported - view

    Hi Elena.

    May I ask where the containxORisORnull() function was defined, in the same formula as the select or in the global function section?

    Fabio

      • Elena_Rodriguez
      • 15 hrs ago
      • Reported - view

       Hi Fabio!
      It's defined in the global function section

    • Sviluppatore Ninox
    • Fabio
    • 13 hrs ago
    • Reported - view

    Hi Elena,

    This is one of those cases where select ... where ... behaves differently in the Web App because the where predicate is evaluated by the server’s query engine. Here are three safe patterns you can use:

    • Client-side filter (to reuse your global function). Good for small/medium volumes:
    (select Asistentes)[containxORisORnull('Company Name', mySearch, myWholeMatch)]
    • Server interpreter (to reuse your global function). Select inside do-as-server:
    do as server
      select Asistentes where containxORisORnull('Company Name', mySearch, myWholeMatch)
    end
    • Server-safe predicate (without your function). Filters directly in the query engine. Fastest at scale:
    select Asistentes
       where if mySearch = null then
          true
        else
           if myWholeMatch = true then
              'Company Name' = mySearch
            else
               contains(lower('Company Name'), lower(mySearch))
            end
        end
    

    In your case contains() seems more suitable to me because you are not making use of regular expressions.

    I hope this helps.

Content aside

  • 13 hrs agoLast active
  • 4Replies
  • 31Views
  • 2 Following