Getting student name and student id in storyline using tincan

Feb 03, 2016

Hi,

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?

Thanks!

 

18 Replies
PRAKASH B

Hi Guys,

I found this solution from the below code.

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);
Steve Flowers

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"
},

Stephanie Harnett

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);

Eric Karnowski

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);
David Kelley

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();

player.SetVar("userName", obj.name[0]);
player.SetVar("userEmail", obj.mbox[0]);