Sign up ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a custom html and javascript file housed within a document library of a subsite: http://teamsite/project/testing%20site/shared%20documents/test.html and

http://teamsite/project/testing%20site/shared%20documents/test.js




function testContext(){
var clientContext = new SP.ClientContext("http://teamsite/projects/testing%20site/");
var oWebsite = clientContext.get_web();
this.collList = oWebsite.get_lists();

clientContext.load(collList);

clientContext.executeQueryAsync(Function.createDelegate(this, this.onWin), Function.createDelegate(this, this.onFail));

function onWin(){alert("Success");}
function onFail(){ alert("Fail");}

Everytime I execute the above I get this error:

SCRIPT5022: Sys.ArgumentException: Value does not fall within the expected range. Parameter name: serverRelativeUrl sp.runtime.js, line 2 character 38258

I've tried several different methods to get CSOM to work in this instance and everytime I get the same error.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

The constructor SP.ClientContext(serverRelativeUrlOrFullUrl) expects serverRelativeUrlOrFullUrl to be the server-relative URL that:

  • starts with /
  • or a full URL that starts with http:// or https://

in SharePoint 2013.

In SharePoint 2010 it could be only the server-relative URL that starts with /.


As an alternative you could utilize:

var ctx = SP.ClientContext.get_current();

to get the current client context of the client-side object model (CSOM) runtime

share|improve this answer
    
This doesn't appear to work because the javascript lives outside of webparts. Code: var ctx = SP.ClientContext.get_current(); var oWebsite = ctx.get_web(); this.collList = oWebsite.get_lists(); clientContext.load(collList); clientContext.executeQueryAsync(Function.createDelegate(this, this.onWin), Function.createDelegate(this, this.onFail)); Throws 2x errors: SCRIPT5007: Unable to get value of the property 'webServerRelativeUrl': object is null or undefined SCRIPT5022: Sys.ArgumentException: Value does not fall within the expected range. Parameter name: serverRelativeUrl –  Patrick Burke Sep 26 '14 at 14:43
    
So assuming the HTML and Javascript are executing out of site/sitename/shareddocuments and the list I want to access is in site/sitename I have attempted absolute URL reference 'site/sitename'; (fails) and the relative URLs '../' and 'site/sitename' and '../.' and all fail. –  Patrick Burke Sep 26 '14 at 14:48
    
Patrick, the url should start with / Please try: /project/testing site/ It is assumed that 'teamsite' is the name of server –  Vadim Gremyachev Sep 26 '14 at 14:50

Use like this:

var siteUrl = '/sites/MySiteCollection';

var clientContext = new SP.ClientContext(siteUrl);

Use relative Url in site url

http://msdn.microsoft.com/en-us/library/office/hh185009(v=office.14).aspx

share|improve this answer
    
Per my example I assume you mean: siteUrl = 'projects/testing%20site' which returns the same error. –  Patrick Burke Sep 26 '14 at 12:46
    
As in example start your url with "/" –  Aanchal Sep 26 '14 at 14:15
    
It appears to have executed but now throws the error: "Request failed. The security validation for this page is invalid and might be corrupted. Please use your browser's Back button to try your operation again. undefined." –  Patrick Burke Sep 26 '14 at 14:56
    
Are you calling this from another site collection or from same site collection. –  Aanchal Sep 26 '14 at 15:00
    
If you turn off the Web Page Security Validation, the security goes away. Manage Web Application----> Select the web application---Click on General Settings(under the ribbon) and turn off the Web Page Security Validation. –  Aanchal Sep 26 '14 at 15:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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