Skip to main content
Participating Frequently
January 31, 2017
Answered

Email quiz results variables in body of an email with JavaScript in Captivate 9

  • January 31, 2017
  • 2 replies
  • 2407 views

This Javascript example works in Captivate 9 to send quiz data to a url: JavaScript Solution: Launch a URL with Captivate Variables as Parameters - CaptivateDev.com  (I've already successfully modified this one to include all quiz results variables)

While this JavaScript example works in Captivate 9  to open our default email (Outlook) and populate the address line, subject line, and body with text but without any quiz results data: Email via Javascript button - Articulate Storyline Discussions - E-Learning Heroes

Now, what everyone actually wants to do with Captivate 9  is to send Captivate 9 quiz results in an html 5 environment via email; however, incredibly Captivate 9 still cannot do this.

However, Articulate with this JavaScript example can apparently do so just fine here: http://matthewbibby.com/email/#filesyoumightneed

Now the following question is for anyone proficient enough in JavaScript in a Captivate 9 context to answer my question:

These are my Captivate quiz results variables:

$$cpQuizInfoTotalProjectPoints$$

$$cpQuizInfoTotalProjectPoints$$

$$cpQuizInfoTotalCorrectAnswers$$

$$cpQuizInfoTotalQuestionsPerProject$$

$$cpQuizInfoQuizPassPercent$$%

$$cpInfoPercentage$$%

$$cpQuizInfoAttempts$$

Now for my questions:

1) Even though the some of the above working JavaScript is intended for Articulate I presume it would also work in Captivate 9, yes?

2)Assuming yes, if I wanted to publish one or more of the above Captivate quiz results variables into the body of a email to be sent to a third party, how would the could we combine the aforementioned JavaScript examples, into a final JavaScript version, that would insert one or more of the above variables coded into the body of the mail along with their text descriptors, so that we get something like the below in the body of an mail?

You-Scored: $$cpQuizInfoTotalProjectPoints$$

Maximum-Score: $$cpQuizInfoTotalProjectPoints$$

Correct-Questions: $$cpQuizInfoTotalCorrectAnswers$$

Total Questions: $$cpQuizInfoTotalQuestionsPerProject$$

Percentage-to-Pass: $$cpQuizInfoQuizPassPercent$$%

Percentage-Scored: $$cpInfoPercentage$$%

Attempts: $$cpQuizInfoAttempts$$

Obviously, in the final output the score values would be visible in lieu of the $$variables$$.

Hope this works, or the alternative may be to switch to Articulate since this company does not want an LMS and is hesitant to use Quiz Analyzer.

    Correct answer harmkuchen

    Here's what I came up with:

    var email="alias@emailaddress.com";

    var subject="CBT Completion Notice";

    var fbk=window.cpAPIInterface.getVariableValue("cpQuizInfoStudentName");

    var Fbk=window.cpAPIInterface.getVariableValue("cpInfoPercentage");

    var body_start="Completed CBT:";

    var body_middle="%0D%0A" + "Name:" + "\xa0" + fbk;

    var body_end="%0D%0A" + "Score:" + "\xa0" + Fbk;

    var mailto_link='mailto:'+email+'?subject='+subject+'&body='+body_start+body_middle+body_end;

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

    Full disclosure: Today is day two of my javascripting experience (I am what the kids call a "n00b," ;)), so if my code isn't elegant, my apologies. What this does, however, is generate an email that autofills: email recipient, email subject, and email body. The email body has three line breaks to help the recipient read the content easier, including the pulled variables out of your responsive project.  You can conceivably add variables(and tweak your subject and body lines) as needed.

    All the user has to do is hit "send."  I have tested this and it works.

    While I recognize LMSs replace this work, I saw a challenge that I wanted to take a stab at.

    I hope this helps.  Cheers!

    --Harm

    2 replies

    harmkuchen
    harmkuchenCorrect answer
    Participant
    January 11, 2018

    Here's what I came up with:

    var email="alias@emailaddress.com";

    var subject="CBT Completion Notice";

    var fbk=window.cpAPIInterface.getVariableValue("cpQuizInfoStudentName");

    var Fbk=window.cpAPIInterface.getVariableValue("cpInfoPercentage");

    var body_start="Completed CBT:";

    var body_middle="%0D%0A" + "Name:" + "\xa0" + fbk;

    var body_end="%0D%0A" + "Score:" + "\xa0" + Fbk;

    var mailto_link='mailto:'+email+'?subject='+subject+'&body='+body_start+body_middle+body_end;

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

    Full disclosure: Today is day two of my javascripting experience (I am what the kids call a "n00b," ;)), so if my code isn't elegant, my apologies. What this does, however, is generate an email that autofills: email recipient, email subject, and email body. The email body has three line breaks to help the recipient read the content easier, including the pulled variables out of your responsive project.  You can conceivably add variables(and tweak your subject and body lines) as needed.

    All the user has to do is hit "send."  I have tested this and it works.

    While I recognize LMSs replace this work, I saw a challenge that I wanted to take a stab at.

    I hope this helps.  Cheers!

    --Harm

    Participant
    March 16, 2018

    Thanks for sharing!!! I'm going to give this a stab.

    Lilybiri
    Legend
    January 31, 2017

    Why do you put the variables between $$? That is the way they appear as placeholder in a text container but the variable name has never $$.  You can download a table with all the system variables from this blog post:

    System variables in Captivate 8/9 - Captivate blog

    The score obtained is cpQuizInfoPointsscored, not cpQuizInfoTotalQuizPoints nor cpQuizInfoTotalProjectPoints

    Participating Frequently
    January 31, 2017

    Thank you for sharing the list.

    Q: Why did I list the variables between double dollar signs?

    A: Because nowhere in the JavaScript discussions at the Captivate or Articulate forums I reviewed did anyone explicitly mention that about CP variables in this context--using the cp prefix instead of having cp variables in between double dollar signs. But then technicians are notorious for glossing over essentials that they take for granted when talking to those less familiar with such matters.