Export table data and backup as a Text file - Forum

Forum Navigation
You need to log in to create posts and topics.

Export table data and backup as a Text file

I need to export the data added to a table as a backup on an Android mobile phone app.

So far I have managed to save a file by using the "cordova-plugin-save-dialog"

I've added <plugin name="cordova-plugin-save-dialog" source="npm" /> as an extra to the additional config.xml codes.

And with the following code, a file can be saved without any issues in the Downloads Folder.

SetVar [SavedText] [MyData]

BeginJS
let blob = new Blob(["[SavedText]"], {type: "text/plain"});
let fileName = "MyBackup.txt";
cordova.plugins.saveDialog.saveFile(blob, fileName).then(uri => {
  console.info("The file has been successfully saved to", uri);
}).catch(reason => {
  console.warn(reason);
});
EndJS

However, what gets written to the created file is just the text "[SavedText]" the variables name, and not the full list items from the table.

I know it's an issue with how I have tried to define the variable for use in the following line:

let blob = new Blob(["[SavedText]"], {type: "text/plain"});

and probably down to what's highlighted in Red, as it's just writing the text added in the "quotes". I've tried all sorts of different ways to add the variable but I can't seem to work out how to add it so the full list items from the table gets written to the text file when it's created.

It's probably a simple formating change to how the variable is coded that's needed, so any advice is appreciated.

Thanks

@paultomo

Getting a variable value from NeoScript into JavaScript is very easy, just prepend $App.
Try this:

let blob = new Blob($App.SavedText, {type: "text/plain"});

Regards.

paultomo has reacted to this post.
paultomo

@luishp

I did try $App.SavedText on it's own but without the [], so was almost there. It's all working now.

Many thanks.

luishp has reacted to this post.
luishp