Forum Discussion

willbogen's avatar
willbogen
Community Member
3 months ago
Solved

My custom javascript cannot pull the Canvas User ID while used in Canvas, but can in SCORM cloud

Hello!  In my Storyline project, we are hosting an artificial intelligence based tutor on an AWS server - to keep some privacy, the start of the URL is https://s3.us-east-2.amazonaws.com and the en...
  • willbogen's avatar
    willbogen
    3 months ago

    Actually, late last night we got it all working pretty good! Based on your initial code, we made the following script to run on the button when it is clicked: 

    // when published as Scorm on a LMS
    	let player = GetPlayer();
    	let lmsAPI = findLMSAPI(this);
    	let myName = lmsAPI.GetStudentID();
    //player.SetVar("newUser", myName);
    //console.log("newUser: "+myName);
    
    window.open("https://s3.us-east-2.amazonaws.com/contentplayer****/Samantha/v2/index.html?context="+myName, "samantha");
    
    //Function to connect with LMSAPI
    function findLMSAPI(win) {
    if (win.hasOwnProperty("GetStudentID")) {
    			return win;
    	}else if (win.parent == win) {
    		return null;
    	}else {
    		return findLMSAPI(win.parent);
    	}
    }

    This fit our goal of retrieving the user ID, and it works totally on its own with no other scripts or required button presses. It does collect all the extra stuff you showed me, but it did collect the 5 digit code from Canvas that I was looking for. 

    Thank you so much for the help, I really really appreciate the assistance!