I want to get student name and id inside my storyline course. I have published in TinCan API output. Is it possible to get student name and id inside the course?
function getParameterByName(name, url) { if (!url) url = window.location.href; name = name.replace(/[\[\]]/g, "\\$&"); var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex.exec(url); if (!results) return null; if (!results[2]) return ''; return decodeURIComponent(results[2].replace(/\+/g, " ")); }
var a =[];var a1 = []; var foo = getParameterByName('actor'); a = foo.split(","); var x=a[0]; a1 = x.split("["); var str = a1[1]; var UName = str.replace(/[^a-zA-Z ]/g, ""); var player = GetPlayer(); player.SetVar("UserName",UName);
I realize this is a bit dated but just wondering how I would obtain student ID with this method. I tried the above for student name and it worked perfectly.
Hi, Stephanie - The agent string is the identifier. The concept of student ID doesn't exist in the LRS. All queries and submission are tied to the actor defined in the statement. This is the value passed into the xapi publish from the content launch and extracted from the URL string in the code above.
I should say, "student ID (a number) isn't a part of the specification". The agent string is the unique identifier. The LRS may contain unique numeric identifiers for each actor. This isn't something we can extract with xAPI calls.
Hey Steve...sorry about the delay and thanks for responding (I didn't have this page bookmarked so didn't see your response). Do you know how I would go about exposing the user email (mbox) using the statements above in addition to the student name?
It comes across as an email but the function of an actor identifier is a unique id for each participant. As long as you're consistent, reports should return consistently:)
Thanks Steve, the client is using Tin Can and I'm publishing that way. The JS code in SL below works work well to pull the student name into a variable but I'd also like to pull in the student email which is the mbox content in the LMS (Absorb). The Absorb people looked at this code and said I needed to change 'actor' to 'name' and to grab email, change 'actor' to 'mbox' - which didn't work. Any help would be really good. : )
function getParameterByName(name, url) { if (!url) url = window.location.href; name = name.replace(/[\[\]]/g, "\\$&"); var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex.exec(url); if (!results) return null; if (!results[2]) return ''; return decodeURIComponent(results[2].replace(/\+/g, " ")); }
var a =[];var a1 = []; var foo = getParameterByName('actor'); a = foo.split(","); var x=a[0]; a1 = x.split("["); var str = a1[1]; var UName = str.replace(/[^a-zA-Z ]/g, ""); var player = GetPlayer(); player.SetVar("UserName",UName);
I've been working on this too, and here's what I figured out. I'm sure it's too late for Stephanie, since that was 4 years ago, but maybe it'll be helpful for someone new.
The method mentioned here uses the URL. There is other information in the URL, and you can pull that out by using the getParameterByName method. In most cases, at least for my test case, nothing else is needed—it's a simple number or text string. Otherwise, you need to use some RegEx or string manipulation.
To get both name and email, this is what I did. Note that I didn't use the RegEx to clean it up, because it could remove characters with diacritical marks or other characters that are not part of a-z or A-Z.
function getParameterByName(name, url) { if (!url) url = window.location.href; // Note: To see the URL so you can see the available parameters, // delete the slashes at the start of the "alert" line below. // It will put up a pop-up, you can copy the url and paste it // elsewhere so you can look at it. Parameters are between ? and =. // alert(url); name = name.replace(/[\[\]]/g, "\\$&"); var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex.exec(url); if (!results) return null; if (!results[2]) return ''; return decodeURIComponent(results[2].replace(/\+/g, " ")); }
var actor = getParameterByName('actor');
// Split the name and mbox portions var actor_split = actor.split(", ");
// Use the name portion and get rid of the extra stuff var full_name_0 = actor_split[0].replace('{"name": ["',""); var full_name = full_name_0.replace('"]',""); var name_split = full_name.split(" "); var first_name = name_split[0]; var last_name = name_split[1];
// Use the mbox portion and get rid of the extra stuff var email_0 = actor_split[1].replace('"mbox": ["mailto:'); var email = email_0.replace('"]}',"");
var player = GetPlayer(); player.SetVar("UserName", full_name); player.SetVar("email", email);
This is my version... it seems to be the simplest and most flexible between different LMS providers.
function getParameterByName(name, url) { if (!url) url = window.location.href; name = name.replace(/[\[\]]/g, "\\$&"); var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex.exec(url); if (!results) return null; if (!results[2]) return ''; return decodeURIComponent(results[2].replace(/\+/g, " ")); }
var foo = getParameterByName('actor');
foo = foo.replace('mailto:','');
const obj = JSON.parse(foo);
//uncomment this section if you want to see all the items that are returned; /*for (const property in obj) { console.log(`${property}: ${obj[property]}`); } */
//here you can set any items that are returned var player = GetPlayer();
18 Replies
Hi Prakash!
Perhaps this thread will be able to assist you.
Thanks for your quick replay Leslie! but this code will be work only SCORM not in TinCan...
Precisely why I'm no JavaScript expert :) I apologize Prakash, and hopefully someone will be able to chime in and assist you here.
Sure Leslie, thanks!
Hi Guys!
Anybody having solution for my question?
I don't know of any way to do this, you could try looking at the API on Rustici's site
Thanks phil! will check..
Hi Guys,
I found this solution from the below code.
Nice one Prakash. I changed the text string on the page to %UserName% and added a Variable of UserName and it works great!
Thanks for sharing
I realize this is a bit dated but just wondering how I would obtain student ID with this method. I tried the above for student name and it worked perfectly.
Hi, Stephanie - The agent string is the identifier. The concept of student ID doesn't exist in the LRS. All queries and submission are tied to the actor defined in the statement. This is the value passed into the xapi publish from the content launch and extracted from the URL string in the code above.
"actor": {
"mbox": "mailto:user.name@org.com",
"name": "Name, User",
"objectType": "Agent"
},
I should say, "student ID (a number) isn't a part of the specification". The agent string is the unique identifier. The LRS may contain unique numeric identifiers for each actor. This isn't something we can extract with xAPI calls.
Hey Steve...sorry about the delay and thanks for responding (I didn't have this page bookmarked so didn't see your response). Do you know how I would go about exposing the user email (mbox) using the statements above in addition to the student name?
SCORM won't expose that. However, you can construct that MBOX for a unique identifier.
last.first@org-name.org
It comes across as an email but the function of an actor identifier is a unique id for each participant. As long as you're consistent, reports should return consistently:)
Thanks Steve, the client is using Tin Can and I'm publishing that way. The JS code in SL below works work well to pull the student name into a variable but I'd also like to pull in the student email which is the mbox content in the LMS (Absorb). The Absorb people looked at this code and said I needed to change 'actor' to 'name' and to grab email, change 'actor' to 'mbox' - which didn't work. Any help would be really good. : )
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
var a =[];var a1 = [];
var foo = getParameterByName('actor');
a = foo.split(",");
var x=a[0];
a1 = x.split("[");
var str = a1[1];
var UName = str.replace(/[^a-zA-Z ]/g, "");
var player = GetPlayer();
player.SetVar("UserName",UName);
Thanks Prakash, It worked for me too.
I've been working on this too, and here's what I figured out. I'm sure it's too late for Stephanie, since that was 4 years ago, but maybe it'll be helpful for someone new.
The method mentioned here uses the URL. There is other information in the URL, and you can pull that out by using the getParameterByName method. In most cases, at least for my test case, nothing else is needed—it's a simple number or text string. Otherwise, you need to use some RegEx or string manipulation.
To get both name and email, this is what I did. Note that I didn't use the RegEx to clean it up, because it could remove characters with diacritical marks or other characters that are not part of a-z or A-Z.
This is my version... it seems to be the simplest and most flexible between different LMS providers.