8

New functions

Hello everyone, 

I put up this post to list all the new undocumented features of Ninox.
I started a post here (https://forum.ninox.com/t/g9hs0n7/v3-7-11-new-functions) but its title limits it to version 3.7. With this more generic name, we can feed the post for all future versions.
 

With version 3.8.x, a new function has appeared and two others have new possibilities...
 

Now both contains() and index() functions accept array :
- contains([any],any)
- index([any],any)

For example, you can use it to find out if a record is in an array of records:

var myCustomer := first(select Customer);

var mySelection := (select Customer where 'First Name' like "s" order by 'First Name' );

contains(mySelection, myCustomer)

return : Yes

And you can see the position of the record in the array :

var myCustomer := first(select Customer );

var mySelection := (select Customer where 'First Name' like "s" order by 'First Name' );

index(mySelection, myCustomer);

return : 3

 

You can also uses it with simple variable :

var a := ["lisa", "roger", "myriam"]
index(a, "roger");

return : 1 


A new function appears : createZipFile(nid,[file],string)

It create a zip file from list of files. In the follow exemple, one ZipFile is created on myDesitnationFiles record. Zip file contain all files of MyCustomer record.

do as server
   var myCustomer := first(select Customer);
   var myDestinationFiles := last(select Customer);
   var myZipName := "allFiles.zip";
   createZipFile( myDestinationFiles, files(myCustomer),myZipName);
end;

Important: createZipFile only works on the server. You have to use in a do as server session

If you want to compress all the files in a record and save it in the same record, everything will be fine the first time. But if you do it a second time, you will include your previous zip file in the new zip file. To avoid this, simply filter your file list as in this example : files(this)[not like myZipName]

do as server
    var myZipName := "allFiles.zip";
    createZipFile( this, files(this)[not like myZipName],myZipName);
end;

4 replies

null
    • Fred
    • 1 yr ago
    • Reported - view

    with such a major change to contains() and index() it is surprising that Ninox didn’t officially mention it. 

    thanks Jacques for exposing the inner workings of Ninox. 

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

    Here is a function that is not new but is not documented. It is the records function that returns multiple records from an array of record numbers. It is the equivalent of the record function, but for a list of records.

    I first thought I could use it with dynamic multi-choice fields, to get the list of selected records with a formula that would look like this:

    records(myTable,numners(myDynicMultiChoice));

    But this was a false joy, because this function has a major flaw which makes it almost useless, namely that the table of registration numbers must be written in hard copy:

    records(myTable,[1,2,3]);

    It is not possible to pass a variable as a parameter (I checked in the Ninox compiler). But I hope Ninox will evolve it so that we can use it for multi choice fields 😀.

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

    Good evening everyone, I just saw a new feature in Ninox that allows you to share the address of a file without having to use fileShare. It's called fileUrl( nid, fileName ).

    var urlOfFile := fileUrl(this, "MyFile.pdf" );

    It returns an address with parameters including the record's ID, the file name, and the user number. I think it's not necessarily a good idea to share this URL with everyone, but for internal use it seems interesting and faster than shareFile.

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

    To retrieve binary files using the http() function :

    In this post (https://forum.ninox.com/t/h7y33v0?r=35y36yp), we discovered that the http() function can return a file in base64 format. This is very useful for retrieving binary data such as image or PDF files. To do this, simply add the 'nx-file': "base64url" option to the request header:

    'uploaded file' := null;
    var fileName := extractx(URL, "\/([^\/?#]+)[^\/]*$", "$1");
    var base64url := do as server
            http("get", URL, {
                'content-type': "application/octet-stream",
                'nx-file': "base64url"
            }, null).result
        end;
    'uploaded file' := importFile(this, text(base64url), fileName)

    Note: The 'nx-file' option is removed from the header before `http()` sends the request. Therefore, the contacted server will not receive this option.

    This option has been available since Ninox version 3.7.11.

    Another thing regarding the `http()` function: In the case where the Content-Type option is set to application/json, the function applies JSON.stringify to the body before sending the request to transform the body content into text.

Content aside

  • 8 Likes
  • 4 mths agoLast active
  • 4Replies
  • 558Views
  • 5 Following