๐Ÿ” Sync Google Sheets XLSForm and Media from Google Drive to ODK Central

Alright folks, buckle up! So @TobiasMcNulty really got my juices flowing when I figured out I could more quickly sync my Google Sheet XLSForm to ODK Central using GoogleAppsScript and the ODK Central API during form editing/development. Here Iโ€™ve expanded that to include a Google Drive folder to upload media associated with an XLSForm.

My ultimate goal is to be able to perform an automated one way sync from Todoist a task management app, to ODK Central so that I can still manage tasks primarily on Todoist, but have tasks w media (audio and image) from a certain filter show up and be removed from a choice list and have this all uploaded to ODK Central without manual intervention. I will make a separate post for that.

Here is a link to the GoogleAppsScript code. There are two separate .gs files.

For the .gs code called Library, you will need to open an AppsScript Editor that is a separate project not bound to any Google Sheet. You can just goto https://script.google.com/home while logged in and Click New Project and paste it in.

Now, for the local .gs, you need to copy and paste into a GoogleAppsScript Editor that is bound to a google sheet, so basically, when youโ€™re in Google Sheets, Go to Extensions โ€“> AppScript Menu and paste that local one in the editor. You will also need to add the Library file by clicking the plus button just to the right of Libraries on the left hand side of the screen. Note that this script assume that the sheet you are in is the active XLSForm you are using to update a Form on ODK Central.

Once the code is ready you need to run SetupConfig once to input your ODK Central and Form details. If these are correct, the only thing that needs to be run (on a trigger) is RunODKMediaSync. There is a dropdown created in your google sheet with these functions as well as ShowProperties to verify everything is looking good. This local code can be copy and pasted on multiple Google Sheets to work on multiple forms at the same time using the same unaltered Library code.

This is the absolute first code project that Iโ€™ve done (Iโ€™m a n00b so take it easy on me :zany_face:) from start to finish and I used ChatGPT to do so. It was definitely a learning process and if people are interested I can share more details about that. Attached is a document outlining what is going on in the code.
SRS Google Drive โ†” ODK Central Media Sync v 1.0.docx (216.8 KB)

Sure there is probably some things in the code that are unnecessary/doesnโ€™t look great, but it WORKS! I would definitely appreciate feedback about the code, good, bad, ugly, etc. I learned there are a lot of ways to cut a :pizza:, but hopefully itโ€™s still good! If there is anything potential dangerous security-wise, definitely let me know! Feel free to modify, make it better, do what you please with it.

1 Like