diff --git a/lib/completionlib.php b/lib/completionlib.php
index f1ffb58..49bed81 100644
--- a/lib/completionlib.php
+++ b/lib/completionlib.php
@@ -471,6 +471,11 @@ class completion_info {
             return;
         }
 
+        // get current user ID if not given
+        if (!$userid) {
+            $userid = $USER->id;
+        }
+
         // Get current value of completion state and do nothing if it's same as
         // the possible result of this change. If the change is to COMPLETE and the
         // current value is one of the COMPLETE_xx subtypes, ignore that as well
@@ -609,7 +614,8 @@ class completion_info {
      * @return void
      */
     public function set_module_viewed($cm, $userid=0) {
-        global $PAGE, $UNITTEST;
+        global $PAGE, $UNITTEST, $USER;
+
         if ($PAGE->headerprinted && empty($UNITTEST->running)) {
             debugging('set_module_viewed must be called before header is printed',
                     DEBUG_DEVELOPER);
@@ -618,6 +624,10 @@ class completion_info {
         if ($cm->completionview == COMPLETION_VIEW_NOT_REQUIRED || !$this->is_enabled($cm)) {
             return;
         }
+        // get current user ID if not given
+        if (!$userid) {
+            $userid = $USER->id;
+        }
         // Get current completion state
         $data = $this->get_data($cm, $userid);
         // If we already viewed it, don't do anything
