I'm attempting to build a script for a Sharepoint 2013 project management hub that eases the process of spinning up and archiving project subsites as they are needed. I'm having trouble getting my archival script to work and very frustrated with the error I'm receiving. I'm storing the javascript file in a library on the top level site so that I can reference the file in the template that the project subsites will be created from.
The idea is that a user on a project subsite will be able to execute the script and do a couple of housekeeping actions. The script file is referenced via a Script Editor web part on a page in the subsite. The first step is to retrieve the current subsite context for things like the subsite title and the subsite url. To make the script usable for all subsites I'm doing this via:
var subsiteCtx = new SP.ClientContext.get_current();
var subWeb = subsiteCtx.get_web();
subsiteCtx.load(subWeb);
subsiteCtx.executeQueryAsync( *callbackfunction*,*callbackfunction*)
When I execute this code I'm receiving:
Error: Sys.ArgumentException: Value does not fall within the expected range.
Parameter name: serverRelativeUrlOrFullUrl
I originally thought this was because I'm executing a script from a file hosted on the top level site but the error persists whether I host the script file on the subsite or paste the code directly in to the script editor web part. When I run the exact same code manually in the browser console I get the desired behavior. What the heck is going on?