Saturday, July 24, 2021

Google Apps Scripts and Schroedinger's cat

Apologies for the title - it's just a tongue-in-cheek reference to the wavefunction collapse referred to in the classic Quantum Mechanics thought example where observing the phenomenon causes it to behave differently - the reference is not really accurate for this bug in Google Docs API, it's just a joke!

The bug - A google doc was being created using a google apps script which copied a template and copied elements from other google docs, and was sometimes resulting in blank output documents. 

The initial observed behaviour was truly bizarre - once the script completes, if we immediately open the  GDoc file it has created, either directly by browsing to My Drive -> Recents and the file , or programmatically by  calling DriveApp to make a copy, the GDoc becomes blank. On the other hand, if we first open another GDoc - it can be any other GDoc - allow it to load fully, close it and then open the newly created GDoc, then the doc is not blank, it has all the data. 

Even after waiting for 5 minutes and then opening the GDoc doesn't help - it becomes blank if the procedure above is not followed. 

If we open another GDoc, but close it before it loads fully, and then open the MLP GDoc, again it becomes blank.

After a lot of trial and error, found that this was due to two separate causes.

1. The template had not been shared with the user running the script as Editor - it was shared as read-only. This was causing the script to return a "Action not allowed" error at the very end of the script just as it exits. getChild(j) and similar functions apparently need Editor access for reliable operation. 

2. If the destination directory is a shared folder, or if the destination folder is open in another window or tab, blank documents result.

The second issue is the one which made me think of Schroedinger's cat. If you watch the document as it is being created, the script behaves differently!

Workaround currently is to create it in a folder not shared with anyone (root folder) and ensure that folder is not open in any other window while the script is running. If the script is interrupted, even documents previously created "successfully" would turn out to be blank. So, we have to ensure the script doesn't time out after half an hour or stop unexpectedly due to any other reason.

Thursday, July 22, 2021

app with notification support - details about Moodle notifications

Copy-pasting from some correspondence about a Moodle site and notifications desired from it, by email and by mobile app notifications - 

1)     Site announcements - The admin user has to go to https://site.org/admin/user/user_bulk.php and choose "all users" and then choose "Send a message" from the dropdown at the bottom.

2)     Calendar events on site - This requires a plugin - https://docs.moodle.org/311/en/Event_reminders

3)     Feedback to designated teacher - Yes, if the teacher enables notifications for this on mobile preferences as well as on the website at https://site.org/message/notificationpreferences.php

4)     Submission of assignments to training admin or designated teacher - Yes, if the teacher enables notifications for this on mobile preferences as well as on the website at https://site.org/message/notificationpreferences.php

5)     Mobile messaging one to one and in group - Yes, if the user enables notifications for this on mobile preferences as well as on the website at https://site.org/message/notificationpreferences.php

6)     Completion of activity to training admin/designated teacher - There is a notification for Quiz completion. Not all activities have it - Yes, if the teacher enables notifications for this on mobile preferences as well as on the website at https://site.org/message/notificationpreferences.php

7)     Course level announcements - The teacher has to send a message to all participants using the method at https://docs.moodle.org/311/en/Messaging#Sending_a_message_to_selected_course_participants . If the user has enabled notifications, they will get notifications if the teacher sends them via this method.

8)     Course level calendar events - This requires a plugin - 
https://moodle.org/plugins/local_reminders

9)     Scheduled chat sessions if installed - The teacher has to send a message to all participants using the method at https://docs.moodle.org/311/en/Messaging#Sending_a_message_to_selected_course_participants .

10)  One to one messaging within a course - Yes, if the user enables it, and if it is enabled by the admin site-wide.

11)  Group messaging within a course - Yes, if the username is known, if not disabled by administrator,

12)  Badge/certificate issued - Yes, if the user enables notifications for this on mobile preferences as well as on the website at https://site.org/message/notificationpreferences.php