Found this content helpful? Log in or sign up to leave a like!

My Hacky Home Campus Solution (using custom JS among others)

rtoon
Community Contributor

We're a really big institution. We have 20+ campuses, each with their locations, all operating as a single institution. A need was identified to be able to record a student's home campus and provide it to LTIs/display it to support staff within Canvas, etc. I couldn't find an existing solution within Canvas so I did a mix of SIS feed updates with some local custom JS to help out.

  • I've never found a reference to the "integration id" field being used in any particular way, so I decided to use this for our students to store their home campus. I took the route of appending a two letter code for their home campus to their existing SIS ID (e.g. C01234567-EV. Integration IDs have to be unique, which is why I embed the SIS ID rather than just the campus code.)
  • LTI Providers have been able to write some custom logic on their end to parse this integration ID and extract the user's home campus form it. (one vendor has us pass it via program_id=$Canvas.user.sisIntegrationId among the additional settings for a dev key.)
  • I then wrote some custom JavaScript to insert the user's home campus to the user details page. Since students can enroll in classes across any of our campuses, this lets our LMS support staff quickly identify to whom to refer students for any local or specific support.Screenshot 2025-07-14 at 2.01.36 PM.png
  • This was accomplished using the following code snippet which I appended to our existing custom JS file. Users with access to the SIS data can see it, users without the access don't see anything.
async function home_campus() {
	if(window.location.pathname.includes("/users/"))
    {
		let user_id = ENV["USER_ID"];
		let integration_id = await getIntegrationId(user_id);
		if (integration_id) {
			let home_campus = integrationIdToCampus(integration_id);
			let tr = document.createElement("tr");
			tr.innerHTML = '<th>Home Campus:</th><td class="home_campus">'+home_campus+'</td>';
			document.querySelector(".time_zone").parentElement.after(tr);
		}
	}
};

async function getIntegrationId(user_id) {
	let response = await fetch('/api/v1/users/' + user_id)
	let data = await response.text();
	data = JSON.parse(data);
	return data["integration_id"];
};

function integrationIdToCampus(integration_id) {
	campus_code = integration_id.split('-')[1];
	switch (campus_code) {
		case "AN":
			return("Anderson");
		case "BL":
			return("Bloomington");
		case "CL":
			return("Columbus");
		case "EV":
			return("Evansville");
		case "DA":
			return("Distance Apprenticeship");
		case "FW":
			return("Fort Wayne");
		case "HC":
			return("Hamilton County");
		case "IN":
			return("Indianapolis");
		case "IO":
			return("IvyOnline");
		case "KM":
			return("Kokomo");
		case "LF":
			return("Lafayette");
		case "LC":
			return("Lake County");
		case "LB":
			return("Lawrenceburg");
		case "MD":
			return("Madison");
		case "MR":
			return("Marion");
		case "MN":
			return("Muncie");
		case "RM":
			return("Richmond");
		case "SL":
			return("Sellersburg");
		case "SE":
			return("South Bend/Elkhart");
		case "SW":
			return("Statewide");
		case "TH":
			return("Terre Haute");
		case "VP":
			return("Valparaiso");
		default:
			return("Undefined"); 
	}
}		

home_campus();

We've had this running for several years and nothing seems to have broken with neither the integration ID nor the custom JS but as always - use with caution, your mileage may vary, objects in mirror are closer than they appear, etc.

Labels (1)