Forum Discussion
JavaScript API update broke my course
I have been using JavaScript to pull in the learners name, date and course to put on a printable custom certificate for regulatory purposes. I updated a course and now I cannot get the JavaScript to work. I am assuming it is the JavaScript API update as nothing else has changed. Is there a list showing old vs. new so I can compare to see what is wrong? I am not an expert in JavaScript and only know enough to get what I need done.
1. First one to get the date
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10) { dd='0'+dd }
if(mm<10) { mm='0'+mm }
today = mm+'/'+dd+'/'+yyyy;
var player = GetPlayer();
player.SetVar("SystemDate",today);
2. Second one to get the name
var player = GetPlayer();
var myName = lmsAPI.GetStudentName();
var array = myName.split(',');
var newName = array[1] + " " + array[0];
player.SetVar("NewName", newName);
3. Last one to create the custom certificate on the certificateBGjpg that I load in the zip file:
myWindow = window.open("","Print","width=780,height=548,scrollbars=0,resizable=0");
varplayer=GetPlayer();
varcourse=player.GetVar("CourseName");
varusername=player.GetVar("NewName");
vardate=player.GetVar("SystemDate");
varcontents ='<html></head><style type="text/css">';
contents+='h3 {font-size:20px; color:#000000;}';
contents+='h2 {font-size:30px; color:#000000;}';
contents+='h4 {font-size:16px; vertical-align:bottom;}';
contents+='#main-content {position:absolute; vertical-align:bottom; width:780px; height:548px; }';
contents+='#userTxt {position: absolute; left: 0; text-align:center; top: 135px; width:780px;}';
contents+='#courseTxt { position: absolute; left: 0; text-align:center; top: 210px; width:780px;}';
contents+='#dateTxt { position: absolute; left: 418px; top: 273px; width: 139px;}';
contents+='</style><body style="margin: 0;">';
contents+='<div id="main-content"><img style="position: absolute; left: 0; top:0; width:780px; height:548px;" src="certificateBG.jpg"; /></div>';
contents+='<div id="userTxt"><h2>'+username+'</h2></div>';
contents+='<div id="courseTxt"><h3>'+course+'</h3></div>';
contents+='<div id="dateTxt"><h3>'+date+'</h3></div>';
contents+='</body></html>';
myWindow.document.write(contents);
myWindow.document.close();
myWindow.focus();
setTimeout(function() { myWindow.print() }, 1000);
Have you checked the console for errors?I would be surprised if it is the API.
What does the console say?
I haven't looked at the code much but I can see missing spaces in the declared variables on 3.
2 Replies
- GlobalFinanceGlCommunity Member
Thank you! I ran my code through the AI for errors and it did locate some. Which is odd since I have been using the same code for the past 3 years and it only now is having issues. It is now working with the corrections! Thank you for your quick reply!
- PhilMayorSuper Hero
Have you checked the console for errors?I would be surprised if it is the API.
What does the console say?
I haven't looked at the code much but I can see missing spaces in the declared variables on 3.
Related Content
- 2 months ago