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

2 Answers 2


Turns out I was misreading my debugger and should have been troubleshooting a nested function that had a typo in it. Such a dumb problem. Thank you for the suggestions regardless.

  • please mark it as an answer - seems like you have answered your own question
    – SandeshR
    Aug 31, 2015 at 21:03
  • I'm not allowed to for another two days.
    – Andrew S
    Aug 31, 2015 at 21:04

May be your script is getting executed before the sp.js loaded completely(including its dependencies). So enclose your code in 'SP.SOD.executeFunc' like

  // your code here

if you are writing this script to get only the site title and url then you can use _spPageContextInfo.webTitle and _spPageContextInfo.webServerRelativeUrl to get the title and URL. you need to enclose your script in '_spBodyOnLoadFunctions.push' to use these variables

  var title = _spPageContextInfo.webTitle;
  var relativeUrl = _spPageContextInfo.webServerRelativeUrl;
  var fullAbsoluteUrl = _spPageContextInfo.webAbsoluteUrl;
  • Tried both of these with no luck. Wrapping the code in your first suggestion returns the same error and while getting the tokens works as suggested there are JSOM queries farther down the line that are giving me the same trouble. It seems like there is something wrong with how I'm referencing the runtimes but given that I'm getting back an error doesn't that indicate that the functions are 'working', albeit not the way I want them to?
    – Andrew S
    Aug 31, 2015 at 16:22
  • I saw this kind of errors when I directly referred sp.js and so.runtime.js using script tags in my page. And they got resolved once I used SOD. Did you add those references directly in page? Aug 31, 2015 at 16:26
  • They are directly in page (inside a script editor web part, but a page nonetheless). I used the same approach on another part of the top level site without issue so I thought I would replicate it here. I guess I misunderstood how the SOD approach works. Do I need to replace each instance of new SP.ClientContext with the SOD wrapper?
    – Andrew S
    Aug 31, 2015 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.