Export data into a Google Drive folder

Has anyone successfully written code to export data to a file on Google Drive through Ignition? I would want to have a gateway script that checks for the data, creates a dataset, and then puts it into a spreadsheet on Google Drive. CSV would also be acceptable. I know how to create the dataset, just no idea how to get it into a spreadsheet on Google Drive.

I’ve done this in the past by setting up Google Drive Backup and Sync on the Ignition gateway. This allows you to save to the synced GDrive folder the same way you would save to any other location on your Gateway’s filesystem. (Take a look at the system.file.saveFile() and system.file.writeFile() functions, just keep in mind that these will need to run on your Gateway to have access to the synced GDrive folder)

To convert your dataset to a CSV you can use system.dataset.exportCSV().

Note: With the GDrive Backup & Sync, you will need to have a user that can be signed in at all times on the Gateway. Anyone with access to the Gateway will be able to access the contents of that synced GDrive folder. I created a stand alone Google user for this purpose.

Hmm, good point. It would be cleaner to use scripting to send it directly to the Google Drive service/API, but your way is probably a lot easier to set up within the Ignition environment.

I found some issue here:

  1. google drive backup app is installed on the gateway machine, windows server OS.
  2. the drive is mounted as G drive.
  3. open the ignition designer, on the script console. I can save file to G drive.
  4. program the script associated to a gateway tag, once the value is true, trigger the script to save file to G drive.
  5. toggle this gateway tag, the scrip is executed, but the file was not saved to the G drive.

What's the difference between executing the same script from the script console and from the gateway directly?

Different user context. Background services' network mappings are independent of logged in desktop users.

This is one of the reasons you should not run the designer on the same system as the gateway--misleading commonality.

thanks for the kind reply, as always.

I am still confused with the scope of usage of the script execution and user rights when the scripts runs.

Can you please advise what should I do to correct this issue?

The service needs to map the google drive. I don't know what is possible for service users and google drives.

(I don't take care of Windows systems. I'll deploy on client-provided Windows systems--I won't provide or maintain Windows itself, or any of its related tech. Others will have to answer--if there is an answer.)

1 Like

Blockquote
Note: With the GDrive Backup & Sync, you will need to have a user that can be signed in at all times on the Gateway. Anyone with access to the Gateway will be able to access the contents of that synced GDrive folder. I created a stand alone Google user for this purpose.

can you explain how you setup this standalone google user?
I am having some issue saving to google drive, it might be related to this setup.