Desire2Learn Bulk Deactivation Script

This script is a Javascript/HTML script that manipulates the Course Information screen of D2L courses through an iframe. This allows us to automate the deactivation of a series of courses. Before using this script, there are a number of things you should be made aware of:

  1. This script MUST reside on the D2L server. You will need to upload it to the Manage Files area of a course and then execute it from there. This is due to security features of web browsers that prevent javascript from operating across different domains.
  2. This script requires a quick Javascript engine. Since the script operates via Javascript, and D2L is JS heavy, it is important that the JS engine be as quick as possible.1)
  3. A quick internet connection is required. Since the script reloads a number of pages, it is important that there isn't too much of a delay between when a page loads of the javascript will fire too early, and won't be able to do things, and the script will halt. More on this in the configuration section.
  4. A non-memory hog browser required. The script loads the D2L pages over and over again using an iframe. So it is important to have a browser that frees memory well when dealing with multiple page loads. As a Linux user, I normally use Firefox to browse the web, and although this script works well in FF, I could only get about 100 courses done before the browser would lock up2). Switching to Google Chrome allowed my to do 1000 courses without problems.

Configuration

Configuration is pretty straight forward. In the loadCourses function, you need to configure the URL to your D2L installation course offering information page, and you may need to modify the checkboxids and buttonids variables depending on the permission levels of your users. Here is a sample of the configuration:

12 |h bulkdeactivate.html
function loadCourses(version){
	if(version == '8.3'){
		url = 'http://yoursite.com/d2l/lms/cmc/course_offering_info_viewedit.d2l?ou=';
		checkboxids = new Array('d_c54','d_c53','d_c52','d_c51');
		buttonids = new Array('d_c67','d_c66','d_c65','d_c64');	
	}
	else if(version == '8.4'){
		url = 'http://yoursite.com/d2l/lp/manageCourses/Course_offering_info_viewedit.d2l?ou=';
		checkboxids = new Array('z_ca','z_t');
		buttonids = new Array('z_d','z_b');	
	}

Modifying checkboxids and buttonids

The D2L pages are constructed based on the permissions the viewing user has on that page. When it draws the interface, it numbers the fields with ids that increase from 1. So if you have users which cannot see certain buttons, the ids of later buttons will be lower then other users who have more permissions. This is why I modified the script to take an array of possible checkbox/button ids, as different courses and different users may be faced with different screens.

This has the benefit of not having to edit the script for each situation, but it also has the potential of slowing things down. If you are dealing with a single configuration most of the time, it might be a good idea to modify that array and put your checkbox/button ids at the top of the list.

It is also possible (depending on what tools you use in your org3)) that the id required for your site is not in the list above and you should add the ids to the front of the list.

Modifying Delay

If you are over a slower connection, and you need to sacrifice speed for reliability, you can modify the delay between loading the page, and trying to operate on that page. You will need to edit line 38 and modify the setTimeout function call:

32 |h bulkdeactivate.html
function loadPage(){
	var iframe = document.getElementById('controlframe');
	iframe.src = url + ous[counter];
	var deactivated = document.getElementById('ousdeactivated');
	deactivated.innerHTML = deactivated.innerHTML + ous[counter] + ',';
	//alert (url + ous[counter]);
	setTimeout ( "updateStatus()", 4000 );
}

The number is the time in milliseconds for the function to update the status to run. By default, that is 4000 ms or 4 seconds.

Running The Script

To run the script you simply upload it to and D2L course through the Manage Files area, and then you open the file. At the top of the page there is a text area that accepts OU numbers of the D2L courses that you wish to deactivate. You paste in a Comma Separated List of the ous, and click the button Load button depending on your version of D2L. Then you click Start Processing to begin deactivating courses.

Then you can just sit back, and let your browser do all of the work. You can continue to use other applications while the script is running, however, anything CPU or Network intensive may interrupt the script.

The Script

You can view the script below, and copy it into your own file for modification.

|h bulkdeactivate.html |h
<html>
<head>
<script type="text/javascript">
var ous;
var counter = 0;
var success = false;
var url;
var checkboxids;
var buttonids;
 
//This function loads up the ous from the text area.
function loadCourses(version){
	if(version == '8.3'){
		url = 'http://yoursite.com/d2l/lms/cmc/course_offering_info_viewedit.d2l?ou=';
		checkboxids = new Array('d_c54','d_c53','d_c52','d_c51');
		buttonids = new Array('d_c67','d_c66','d_c65','d_c64');	
	}
	else if(version == '8.4'){
		url = 'http://yoursite.com/d2l/lp/manageCourses/Course_offering_info_viewedit.d2l?ou=';
		checkboxids = new Array('z_ca','z_t');
		buttonids = new Array('z_d','z_b');	
	}
	var oustext = document.getElementById('ous').value;
	//Split the ous on , and add to the ous array
	//alert(oustext);
	ous = oustext.split(',');
	document.getElementById('oustodeactivate').innerHTML = oustext;
	document.getElementById('step1').style.display = 'none';
	document.getElementById('step2').style.display = 'block';
}
 
function loadPage(){
	var iframe = document.getElementById('controlframe');
	iframe.src = url + ous[counter];
	var deactivated = document.getElementById('ousdeactivated');
	deactivated.innerHTML = deactivated.innerHTML + ous[counter] + ',';
	//alert (url + ous[counter]);
	setTimeout ( "updateStatus()", 4000 );
}
 
function updateStatus(){
	for (i in checkboxids){
		var checkbox = window.frames['controlframe'].document.getElementById(checkboxids[i]);
		if(checkbox.name == 'active'){
			checkbox.checked = false;
			success = true;
			break;
		}
	}
	if(success == false){
		alert("Can't find the active check box.  You will need to edit this script manually.");
		exit();
	}
 
	success = false;
 
	for (i in buttonids){
		var button = window.frames['controlframe'].document.getElementById(buttonids[i]);
		if(button != null){
			button.click();
			success = true;
			break;
		}
	}
 
	if(success == false){
		alert("Can't find the Save button.  You will need to edit this script manually.");
		exit();
	}
 
	if(counter == ous.length - 1){
		//Stop Processing
		alert('Deactivated ' + (counter + 1) + ' Courses.');
	}
	else{
		counter++;
		setTimeout ( "loadPage()", 4000 );
	}
}
</script>
</head>
<body>
<p>
	This page will allow you to bulk deactivate a series of courses in D2L.  
</p>
<div id="step1">
	<p>
		First you will need to list your ou numbers for the courses you want to deactivate 
		in the text area below.  This should be a comma separated list of ou numbers (EX: 
		<em>6630,15528,7038</em>):
	</p>
	<textarea id="ous" name="ous" cols="100" rows="4"></textarea><br />
	<input type="button" id="loadbutton" onclick="loadCourses('8.3');" value="Load Up Courses (D2L 8.3)" /> 
	<input type="button" id="loadbutton" onclick="loadCourses('8.4');" value="Load Up Courses (D2L 8.4)" />
</div>
<div id="step2" style="display: none;">
	<input type="button" id="startbutton" onclick="loadPage();" value="Start Processing" />
	<br />
	To Deactivate: <span id="oustodeactivate"></span><br />
	Deactivated: <span id="ousdeactivated" style="text-decoration: line-through;"></span>
</div>
<iframe id='controlframe' name='controlframe' src="" width="85%" height="600px">
 
</iframe>
</body>
</html>

Frequently Asked Questions

Q1: How do I get OU Numbers?

Getting OU numbers can be tricky because they are the internal identifier D2L users to address courses, and probably aren't linked in any way to the internal numbers/names your organization will use. You will notice the ou number in the URL of courses as ou=#####.

We run a report using the reporting tool that gives us the ou numbers (in one, non-ideal form).

In the Reporting tool, create a report using the Org Units dataset. With in the report, include the column for the course Path. This path contains the OU number for the course. Under the filter tab, add a few filters that will narrow down your search to the information you require. Our organization adds a semester code to all of our courses, so all courses that end in 200802 are courses that ran in the last semester. We can query these courses, and get a list of the ou numbers through the course offering paths. See below for some images of our report in action.

Then you have to do some work in manipulating the report to filter out the OU numbers. I select the whole column using firefox, and dump it into OpenOffice. Customize the import to break the lines on all of the dividing characters, and then I have a column of ou numbers. Then take that, and add in commas after all of the entries using a find and replace. You will need a text editor that can find and replace on characters you cannot see. Replace the new lines with commas.

Comments?

If you have any questions or comments on how to use the script, please post them on my blog post on this topic at: http://www.cornempire.net/2009/07/07/d2l-bulk-deactivation-part-2/

1) Google Chrome is recommended. This script was tested using the Linux Dev version of Chrome. It also works well in Firefox, but FF has other issues as listed below
2) using Firefox 3.0
3) I noticed this when we had Intelligent Agents enabled
d2l/bulkdeactivate.txt · Last modified: 2010/10/01 19:59 (external edit)
CC Attribution-Noncommercial-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0