Forum Discussion

RickPitman's avatar
RickPitman
Community Member
4 years ago

Need some help with JavaScript

I am creating a course that is a new hire "check-in" for a weekly update on progress.  Essentially each week the learner will log in and complete a short status update on specific categories with their supervisor.  Here is my JS, but i just simply doesn't run.  Any help would be appreciated!

 

var player = GetPlayer();

var email = "myemail@email.com";

var subject = "SSE Day 1" ;

var ee_id = Player.GetVar(EEIDNumber);

var Super = Player.GetVar(SupervisorName);

var Super_ID = Player.GetVar(Super_ID);

var Safety = Player.GetVar(Safety_Rating);

var Instructions = Player.GetVar(Inst_Rating);

var Productivity = Player.GetVar(Productivity_Rating);

var Teamwork = Player.GetVar(Teamwork_Rating);

var Proff = Player.GetVar(Proff_Rating);

var Feedback = Player.GetVar(Feedback);

var body_start = "The following answers are from the course";

var body_middle1 = "EE ID: ";

var body_middle2 = "Supervisor Name: ";

var body_middle3 = "Supervisor ID: ";

var body_middle4 = "Safety Rating: ";

var body_middle5 = "Following Instructions: ";

var body_middle6 = "Productivity: ";

var body_middle7 = "Teamwork: ";

var body_middle8 = "Professionalism: ";

var body_middle9 = "Feedback: ";

var cr = "\n";

var body_end = "Please save these answers in an email folder for future reference.\n";

var mailto_link = 'mailto:' +email+'?subject='+subject+'&body='+encodeURIComponent(body_start +body_middle1 +EE_ID +cr +body_middle2 +Super +cr +body_middle2 +Super +cr +body_middle3 +Super_ID +cr +body_middle4 +Safety +cr +body_middle5 +Instructions +cr +body_middle6 +Productivity +cr +body_middle7 +Teamwork +cr +body_middle8 +Proff +cr +body_middle9 +Feedback +cr + body_end);

win = window.open(mailto_link, 'emailWin')

  • JoeFrancis's avatar
    JoeFrancis
    Community Member

    The first thing that immediately pops out is that you created a new variable (player), but then refered to Player. JavaScript is case sensitive, so player, Player, and PLAYER are 3 different variables.

    Next. the variable you are referencing within the parentheses needs to be wrapped in double-quotes. e.g,

    var ee_id = player.GetVar("EEIDNumber");

     

  • JoeFrancis's avatar
    JoeFrancis
    Community Member

    This discussion should help you get started.

    Email Trigger

    Note how Walt Hamilton addressed carriage returns and line feeds by using URL-encoding.

    %0D = Carriage return
    %0A = Line feed

    I recently put together something similar, and I started by breaking it into smaller, working chunks until I ran into something which "broke the code." Literally, I started with hard-coded Email address, Subject, and Body, and invoked the mailto: command from Storyline. Once that worked, then I began substituting variables for hard-code and adding more retrieved variable values.

  • RickPitman's avatar
    RickPitman
    Community Member

    Thank you for the help!  I will try to see where I can "break it".