Write data to file
I want to write data to a file. Basically, iterate through the selected records and create a file and write the exact data I require, in the specified way. This would be relatively simple in a *nix shell script (other programming languages are available), but at first glance it seems beyond Ninox's ability as it seems to have only very simplistic print and/or export options that I've not had need to study before.
I originally used individual text files to store the data and then a simple script to write what I needed to a file, but being data, I assumed Ninox was the better tool, further assuming I could create the required scripting to manipulate the data and write the file. Was I wrong?
12 replies
-
Do you want to save a file in your Ninox record or on your computer?
-
And with this code (and NativeJS from Ninext), you can also download it automatically and without the white window:
"----------------------------
Download file
-----------------------------";
function downloadFile(fileNinox : file,destFileName : text) do
#{:text:callback
// separate the table id, the record number and the file name
var file = util.parseNIDFile(fileNinox);
// If the destination of the file name is not defined, it is set as the current name by default.
if (!destFileName) destFileName = file[2];
// create the URL of the file
database.downloadURL1(fileNinox)
.then((fileURL) => {
fetch(fileURL)
.then(resp => resp.blob())
.then(blob => {
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = destFileName;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
callback(url.url);
})
});}#
end; -
I wasn't sure what you were getting at about downloading, but having tested further with the createTextFile function, it appears it is not possible to create the text file where you actually want it. So far I've only been able to create it as an attachment, which is NOT what I want.
Creating the file works perfectly and it contains what I want, but buried in Ninox's folder hierarchy is no good at all. Well, I could then manually save it elsewhere, but if they expect manual intervention, why not just tell us to simply type the *** file in the first place.
The Manual gives little help as "createTextFile(nid, string, string)" is less than helpful when they do not define what those strings are. Doh!
Looking at the examples, it then states:-
"If you don鈥檛 define where the new file should be saved (as you do in this example), it will be attached to the record."
I took that to mean that if you only provide a filename, it will be saved as an attachment, but a full path would "define where the new file should be saved". Apparently not.
When I supplied the full path, the script executed with no error, but no file either. No attachment and nothing of that name saved anywhere on the Mac. At least that I can find.
So have Ninox provided a useful function, but then crippled it by only allowing it to be created as an attachment, rather than where you actually need it? How dumb is that, especially when the Manual implies it IS possible to "define where the new file should be saved". Except it looks like you cannot.
Jacques TUR , I don't, for this db, want to get involved in externals like your Ninext, but am I right that Ninox will not allow you to save a created file where you want it?
-
Basically, as far as I can see, if there's a '/' in the last string (filename), Ninox simply does nothing. No error, but doesn't create the file.
Someone tell me I'm wrong please.
-
Use createTextFile with importFile :
File := createTextFile(this, raw('Rich text'), "MyTextFileExample.html");
importFile(this, File
); -
UKenGB said:
especially as the user manual clearly implies that you can do this.Where ? Can you send me a link ?
As far as I know, it is not possible to save a file to the computer's disk from Ninox without the user's intervention (or else you have to go through code or a server that allows this). -
Sean said:
I agree, it would be nice if Ninox implemented an option to use the "Save as" dialog.Vous pouvez le faire en cr茅ant une url avec shareFile et un bouton de t茅l茅chargement avec une formule html (sans Ninext). Here is the code to put in the formula. It also has the advantage of not opening an empty window.
var s := mySharedFile; var myDestFileName := "image.jpg"; html(" <script> function downloadFile(fileURL, destFileName) { debugger; fetch(fileURL) .then(resp => resp.blob()) .then(blob => { const url = window.URL.createObjectURL(blob); const a = document.createElement('a'); a.style.display = 'none'; a.href = url; a.download = destFileName; document.body.appendChild(a); a.click(); window.URL.revokeObjectURL(url); }) }; </script> <button onclick=""debugger; downloadFile('" + mySharedFile + "', '" + myDestFileName + "')""> donwload me </button>")
Content aside
- 1 yr agoLast active
- 12Replies
- 326Views
-
4
Following