0

Function parameters - which types are possible

I've found this old post 

https://ninox.com/en/forum/technical-help-5ab8fe445fe2b42b7dd39ee7/types-of-parameters-for-a-private-function-5c0962c08d9fa6683abafc7d

And not really any docs on the topic.

Any changes on this?

Being able to call a function with parameters record, records, arrays, JSON - without workarounds is requested.

 

Thx 

Jesper

12replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • The possible types for a function are : 

    • text 
    • number
    • date
    • datetime
    • time
    • timeinterval
    • appointment
    • boolean
    • html
    • color
    • icon
    • email
    • phone
    • location
    • file
    • user
    • any

    with user type, you could call with single user or array of user : 

    function myFunction(myUser : user) do
        userName(myUser)
    end;
    myFunction(user())
    

    or 

    function myFunction(myUsers : user) do
        join(for u in myUsers do
            userFullName(u)
        end, ", ")
    end;
    myFunction(users())
    

     

    With the any type you can call with a JSON variable :

    function myFunction(a : any) do
        capitalize(text(a.firsName)) + " " + upper(text(a.lastName))
    end;
    myFunction({
            firsName: "Jacques",
            lastName: "TUR"
        })
    

    You can also call with array of JSON variable :

    function myFunction(t : any) do
        "// recover the array from JSON array";
        "// and return the array filtred and sorted";
        var c := for i in t.table do
                i
            end;
        c[lastName like "T"] order by this.firstName
    end;
    "//call with array of JSON";
    myFunction({
            table: (select Customer).[{
                    firstName: 'First Name',
                    lastName: 'Last Name'
                }]
        })
    

    And, of course, call with table result :

    function myFunction(t : any) do
        "// constructs an array of records identical to the one obtained with the Select function";
        "// the ID number is gotten by keeping only the number part in order to call the Record function";
        var c := for i in t.table do
                record(Customer,number(extractx(text(i), "\d.*")))
            end;
        c.('First Name' + c.'Last Name')
    end;
    myFunction({
            table: select Customer
        })
    
    Like 3
    • Sean
    • Sean
    • 3 mths ago
    • Reported - view

    Wow, thanks Jacques! I think Ninox still has some work to do with their documentation. 馃槃

    Like 1
    • Sean
    • Sean
    • 2 days ago
    • Reported - view

    Jacques TUR In the last example, do you know of a way to substitute the actual table name in the record() function? Otherwise, you might as well just use the select statement in the function definition. Thx

    Like
    • Sean I'm not sure I understand your question. Can you tell me what you would like to achieve?

      Like
      • Sean
      • Sean
      • yesterday
      • Reported - view

      Hi Jacques, In the record() function you use Customer for the table name. To me, that seems to be hard coding the function. Do you know if there is a way to use a variable there?

      Like
    • Sean something like that ?

      function myFunction(tableName : text,fieldName : text,filter : text) do
          var c := eval("select " + tableName + " where " + fieldName + " like " + filter, this);
          c
      end;
      myFunction("Customer", "'First name'", "A")

      Like
      • Sean
      • Sean
      • yesterday
      • Reported - view

      Jacques TUR I don't think that will work in a global context. I get...

      "Keyword not defined in this context: this at line 2, column 90"

      when I use it in the Console. I tried using t.caption since that is where the table name is stored in the database schema, but it doesn't return anything. I'm going to be out of touch for a while.

      Like
    • Sean yes, of course "this" does not exist in the console. You have to replace it with another record number, like "first(select Customer)".

      Like
      • Sean
      • Sean
      • yesterday
      • Reported - view

      Jacques TUR That鈥檚 not what what I am asking about.

      Like
    • Sean Sorry, I misunderstood. Can you send me your code?

      Like
      • Sean
      • Sean
      • yesterday
      • Reported - view

      Jacques TUR 

      Like
    • Sean 

      I think it can be done with the eval() function (Haven鈥檛 try it though).

      let code:= 鈥渞ecord(鈥+ FieldContainingYourTablename+鈥,number(extractx(text(i),鈥濃漒d.*鈥濃)))鈥;

      eval(code,this)

      Steven

      Like
Like Follow
  • 18 hrs agoLast active
  • 12Replies
  • 461Views
  • 4 Following