4

v3.7.11 new functions

setItem(any,string,any) and removeItem(any,string)

These two functions allow to manipulate JSON by adding or removing an item. This is very good news, because until now this was only done using JavaScript.

var a := {};
setItem(a, "hello", 1);
setItem(a, "goodbye", 2);
a;

 

Copy

 

 result : {"hello":1,"goodbye":2}

removeItem(a, "goodbye");
a;

 

Copy

 

result : {"hello":1}

 

http(string,string,any,any,[any]) and http(string,string,any,[any])

allows to send multipart requests with one or more files. I don't know yet how to use these functions.

loadFileAsBase64(file) and loadFileAsBase64(nid,string) and loadFileAsBase64URL(file) and loadFileAsBase64URL(nid,string)

These functions allow to read files or URLs in base 64

=> Since v1.7.10 : 

length([any])

Originally this function was intended to return the length of a text. Now it can also return the number of elements in an array.

There is a difference between length and count. Count will check one by one if each element of the array is neither null nor an empty string. For example, count(["1", ""]) will return 1 while length will return 2.

This individual check takes a lot of time, especially if the board is large. 

For example, using length(select Customer) is 100 times faster than count(select Customer). When the table is small, this is not very significant, but when it has many elements (over 1000), it can take a long time.

Since we discovered the possibility to use filters in tables, it is not uncommon to see formulas like (thank you Fred for the code ;o)

let c := Table2;
let lm := numbers(pMultichoice);
c[var v := numbers(cMultichoice);
    count(v[(var subv := this;
                count(lm[= subv] > 0)) > 0])]

 

Copy

 

Here the count function is used in a nested way. If the arrays are large, then the computation time will be very long. 

By using length instead of count, the result will be the same, but the execution time will be drastically reduced.

let c := Table2;
let lm := numbers(pMultichoice);
c[var v := numbers(cMultichoice);
    length(v[(var subv := this;
                length(lm[= subv] > 0)) > 0])]

 

Copy

 

=> Before 3.7.1

I also wanted to tell you about these two functions that are not documented in Ninox:

typeof([any]) or typeof(any)

Returns the value type of the passed parameter:

var a := 10;
typeof(a)

 

Copy

 

return : "number"

If the parameter is a function, typeof returns the type of value that the function returns.

function test() do
    first(select Inscriptions)
end;
typeof(test())

 

Copy

 

return : "nid"

get(nid,string)

Returns the value of the field whose name is passed in parameter :

var name := "First Name";
get(first(select customer), name);

 

Copy

 

return : Sofia

This function can be very useful to create parametric views: 

9 replies

null
    • Fred
    • 1 yr ago
    • Reported - view

    How did you find these new functions? Ninox is horrible about documenting changes.

     

    Jacques TUR said:
    Since we discovered the possibility to use filters in tables, it is not uncommon to see formulas like (thank you Fred for the code ;o)

     Actually, it is just your code that I "rediscovered". I just couldn't process it when you originally wrote it.

    • Ninox developper
    • Jacques_TUR
    • 1 yr ago
    • Reported - view
    Fred said:
    How did you find these new functions? Ninox is horrible about documenting changes

    On the source code of Ninox.  It is easily accessible on cloud version. 

    • Fred
    • 1 yr ago
    • Reported - view

    For the get() function, can you share your code for the view? I’m wondering how you changing of the view column. Is it a new view for each option of the choice field?

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

      Fred Here is the code that is in the formula in the User Choice column:

      get(this, text(first(select 'Test choice').Choice))
      
    • Lead Developer
    • schwendtner
    • 11 mths ago
    • Reported - view

    Jacques TUR do you have any idea, how to setItem in a nested object? It works like a charm in a plain key/value json, but if we add some layers, figuring out the correct (if any) accessor was not successful. 

      • Lead Developer
      • schwendtner
      • 11 mths ago
      • Reported - view

       After thinking about it for a couple minutes, i figured it out and this topic is solved:

      • Ninox developper
      • Jacques_TUR
      • 11 mths ago
      • Reported - view

      Florian Schwendtner You can also write this : 

      var watermark := json.Handlebars.Watermark;
      setItem(watermark, "Template", "Y");
      
    • Marcel_Reeg
    • 6 mths ago
    • Reported - view

    Hello   ,

    I was looking for a way to send API requests with the content type "multipart/form-data" from Ninox and came across your post:

    "http(string,string,any,any,[any]) and http(string,string,any,[any])

    allows to send multipart requests with one or more files. I don't know yet how to use these functions."

    Could you figure out how to use those functions or are there are other ways to construct multipart requests (text or files)? I'm trying something similar to this (https://helpcenter.veeam.com/docs/vac/rest/oauth.html?ver=70#example-requests-and-responses).

      • Ninox developper
      • Jacques_TUR
      • 6 mths ago
      • Reported - view

       Sorry, but I've never used the Rest API with multi-part files. However, have you looked at the documentation (https://docs.ninox.com/en/script/functions-overview/functions/http)? It indicates which parameters to pass to the http function.
      Otherwise, you can also ask technical support.

Content aside

  • 4 Likes
  • 6 mths agoLast active
  • 9Replies
  • 639Views
  • 5 Following