How to send quiz results via mail automatically via Javascript

Nov 25, 2020

Hi all,

until now I am able to let create a mail with the results of 5 quizzes automatically.

But the learner could adapt that mail text and has to hit the "Send"-button in his mail client.

How to send the mail automatically?

What I did to let it work so far:

1. Created 5 global variables (r1, r2,...r5) in which the resultvalues are stored

2. Created 5 events ("r1 = Results.ScorePercent", "r2 = Results1.ScorePercent"...) to store the result values in these global variables

3. Assigned this Javascript code to a button:

var player = GetPlayer();
var status=player.GetVar("completion");
var email = 'recepientsmailaddress@here.com';
var r1 = player.GetVar('r1');
var r2 = player.GetVar('r2');
var r3 = player.GetVar('r3');
var r4 = player.GetVar('r4');
var r5 = player.GetVar('r5');
var subject = 'My quiz results of XYZ Quiz';
var emailBody = 'My quiz results:' + " " + r1 + ", " + r2 + ", " + r3 + ", " + r4 + ", " + r5;
window.location.href='mailto:'+email+'?subject='+subject+'&body='+encodeURIComponent(emailBody);

14 Replies
Josh Dean

I tested the code above after I created a few variables (r1,r2, etc.) to match yours.

I would remind that JavaScript only runs when the project is published. You can also add a JavaScript alert to generated a popup to display a value to check how things are working. With this approach you can see the value of variables along the way. console.log can help with this too if you need many alerts.

alert("The value of results at this point is " + results.toString())

 

Your code worked well for me so I'd guess your variables aren't getting assigned from your quiz results in the earlier step.

I also updated your version a little using an Array.toString() function that easily lists a series of variables. Hopefully it's useful to someone.

var player = GetPlayer();
var status=player.GetVar("completion");
var email = 'recepientsmailaddress@here.com';
results = [
player.GetVar('r1'),
player.GetVar('r2'),
player.GetVar('r3'),
player.GetVar('r4'),
player.GetVar('r5')
];

alert("The value of results at this point is " + results.toString())

var subject = 'My quiz results of XYZ Quiz';
var emailBody = 'My quiz results:' + results.toString();
window.location.href='mailto:'+email+'?subject='+subject+'&body='+encodeURIComponent(emailBody);
Rhonda Lendt

Ah, I see that this will print the 'Results.ScorePercent'. But what I am hoping for is the actual quiz showing the user's answers and score. If we use the Print button it will print a great report.html. But how do we get that in an email without users having to download and locate file to email? Still digging, but if anyone knows, I would love to hear! Trying to find an easy way for Learners to submit their quiz records. Thanks! :)

Meera Lynn
Rhonda Lendt

Hi Meera Lyn,

Your issue is very similar to mine. Did you ever figure out how to send the results via email?
Thanks kindly,

Hi Rhonda

Articulate Support recommended that the company has the course hosted on their LMS (Learning Management System)  - LMS will send out notifications like this, and therefore, Articulate does not need to have this functionality (shame really).

As a workaround, what we did is to have a Print button on the Results slide. When the user clicks Print, it loads the final A4 portrait slide which has Javascript containing: the course title +  the date of the course + the score the user got (you could also set up a user name parameter at the beginning of your course to get the user to enter their name before they start the course - this name field can then also be entered on the afore-mentioned final slide that contains their score).

When the user clicks the Print button on the Results slide, Javascript launches the print dialogue screen allowing the User to print this A4 portrait slide for their record, or if they wish to save it in their local drive they can simply amend the "Destination" drop-down to PDF format and save it that way. 

Our print button Javascript is: 

var styles = `@media print {

body, * { visibility: hidden; }
html, body { overflow: hidden; transform: translateZ(0); }
#slide {
transform: scale(1.1) !important;
}
#wrapper {
transform: scale(1) !important;
}
#slide,

#wrapper {
width: 100% !important;
height: 100% !important;
overflow: visible !important;
}
#frame {
overflow: visible !important;
}
.slide-transition-container {
overflow: visible !important;
}
@page {size: A4 portrait;max-height:99%; max-width:99%}
.slide-container, .slide-container * {
visibility: visible !important;
margin-top: 0px !important;
margin-left: 0px !important;
}
#outline-panel {
display: none !important;
}
}
}`
var stylesheet = document.createElement('style');
stylesheet.type = 'text/css';
stylesheet.innerText = styles;
document.head.appendChild(stylesheet);
window.print();

 

Best wishes.

Meera Lynn
Rhonda Bear

Thank you so much for sharing! What a great Articulate community! Very
much appreciated!

I will try that out for sure :)

Best regards,

Rhonda

I hope my suggestion helps you Rhonda.

Like you, I also strived for a while, to find the emailed solution but this was not supported by Articulate. 

T H

Dear Karin and all,

this javascript is definitely working and showing each quiz question result (true means the questions was answered incorrectly)

I created for each Question a variable like "Q5_2" what means Questions Number 2 of the 5th Chapter in the module. So I know what questions it is.

Then the 5 events are created on the very final result slide when timeline starts by "if variable changes then assign the Score Percentage to the variable r1" and so on. 

So I am just filling all 5 variables with the 5 score percentages as I have 5 result slides within my module. You perhaps need just one.

Then in the end the learner hits the button, the javascript starts and creates the email with subject, and email text. Email text contains after Validation Code 1 the passing percentages. But I somekind of pasted filling figures to not let the learner understand that these are his final results. So he is not able to modify them.

After validation code 2 each question results are shown with the number of the question. true means a correct answer. False an incorrect answer.

See attached screenshot (German) of an example of a generated email. This is created after the learner hits a button that starts the following javascript.

Good Luck ;)

T H

Uhhhh...this is going to get big. 

Actually it should work, getting the answers. But it would mean you have to create on each answer a hotspot. Then create for each hotspot a variable. Then you have to create a trigger that starts with timeline start of the slide. That trigger says "on click on hotspot 1 assign value of variable 1 to true". So you would see which of the hotspots have been clicked.'

And of course you have to add these variable to the javascript.

But this only works if you turn off the randomization of the order of the answers. They have to be static.

Thorsten

Karin H

Okeeeee... :D As I'm having over 80 questions that would be far too much work to do in my eyes. ;) . Better I go first back to the department who has the need for that e-learning to ask them if they really need that. Or if we just make a combination of mail and the standard result sheet... Naming the answers in a way, the learner doesn't figure out which answers are meant.

But thanks a lot for showing me this way. I wouldn't have thought of it. Learned something today. :)