How to send quiz results via mail automatically via Javascript

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

8 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.