Forum Discussion
Importing variables from excel online (Power Automate / Json)
- 2 months ago
Thought I'd try and share the link another way :)
https://www.loom.com/share/00c6a054661b470eb7039366ba367550?sid=2b4613ef-dca1-46fa-a530-d195b734e789&fbclid=IwY2xjawIqobhleHRuA2FlbQIxMAABHY7MLjSVtyKowcQf4G87tEfkagP6Pgkq8-OirfKapYV1Cwaf2NAar7eacw_aem_Q_m8-aVKCGe8NOnxkI-GLQ
// Function to retrieve the profile and set variables in Storyline async function retrieveProfile() { var player = parent.GetPlayer(); // Initialize player here try { // Access the storyline player object function findLMSAPI(win) { // look in this window if (win.hasOwnProperty("GetStudentID")) return win; // all done if no parent else if (win.parent == win) return null; // climb up to parent window & look there else return findLMSAPI(win.parent); } var lmsAPI = findLMSAPI(this); var sID = lmsAPI.GetStudentID(); console.log("Email Address from Storyline:", myEmail); // Debugging log // Power Automate URL var url = "Put your URL here"; // Send the POST request to Power Automate let response = await fetch(url, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email: sID }) // Payload with email }); // Parse the JSON response let data = await response.json(); console.log("Response from Power Automate:", data); // Debugging log if (response.ok && data.success) { console.log("Profile retrieved successfully!"); // Helper function to handle boolean conversion function toBoolean(value) { if (value === "TRUE" || value === "true" || value === true) return true; return false; } // Set variables in Storyline from the response // Example 1 player.SetVar("variable 1", true); // Example 2 player.SetVar("variable 2", toBoolean(data.purpose1)); // Delay the setting of ProfileCreated to "Loaded" to allow time for the variables to update setTimeout(function() { player.SetVar("ProfileCreated", "Loaded"); console.log("ProfileCreated Variable set to 'loaded'."); }, 1500); // 500 millisecond delay } else { console.log("Profile not found or error in response."); player.SetVar("ProfileCreated", "Profile Not Found"); } } catch (error) { console.error("Error retrieving profile:", error); player.SetVar("ProfileCreated", "Error"); } } // Trigger the function when the page loads window.onload = retrieveProfile;
Tia Pez did this video breakdown for me that's on Storyline fb forum, although the link is in Loom. I can't seem to share it. So I've posted the script in the reply. I've alter a few variables. So apologies if it requires a once over, but it should work for anyone using it via an LMS if they don't have CORS policy stoppi
Unfortunately and I'm in the process of asking our security team if they'll allow this access to retrieve. If not, then although this might help some others. I ran into a dead end as I have no other way to store/retreive the data at a later date.
Thought I'd try and share the link another way :)
https://www.loom.com/share/00c6a054661b470eb7039366ba367550?sid=2b4613ef-dca1-46fa-a530-d195b734e789&fbclid=IwY2xjawIqobhleHRuA2FlbQIxMAABHY7MLjSVtyKowcQf4G87tEfkagP6Pgkq8-OirfKapYV1Cwaf2NAar7eacw_aem_Q_m8-aVKCGe8NOnxkI-GLQ