Skip to main content
added 10 characters in body
Source Link
Robert Lindgren
  • 24.5k
  • 12
  • 53
  • 79

I am busy writing some javascript to take a list of selected documents and do some processing on a list with each document in Office365. I am getting a strange error when the code tries to load the document from the absolute URL. theThe document is guaranteed to be in the same SP.WebSP.Web that the JS is in.

The error is "Value does not fall within the expected range."

Value does not fall within the expected range.

Below is the JS I have:

function GetFile(attachment, item) {
   var fileContext = SP.ClientContext.get_current();

   var site = fileContext.get_site();
   fileContext.load(site);

   fileContext.executeQueryAsync(function() {
       var relUrl = attachment.Url.replace(_spPageContextInfo.siteAbsoluteUrl, '');
    
       var file = fileContext.get_web().getFileByServerRelativeUrl(relUrl);

       fileContext.load(file, 'ListItemAllFields');
    
       fileContext.executeQueryAsync(
           function () {
               var listItem = file.get_listItemAllFields(); 
           },
           function (sender, args) {
               console.log(args.get_message()); //errorhandling
           }
       );
   }, function(sender, args) {
       console.log(args.get_message());
   });  
}

thisThis is not a permissions thing as I can take the urlsurl of the documents being selected and open them fine from the browser. 

I have noticed, that I can't seem to hit the client.svcclient.svc service on the site in question when taking the url for the request from the request object.

I am busy writing some javascript to take a list of selected documents and do some processing on a list with each document in Office365. I am getting a strange error when the code tries to load the document from the absolute URL. the document is guaranteed to be in the same SP.Web that the JS is in.

The error is "Value does not fall within the expected range."

Below is the JS I have:

function GetFile(attachment, item) {
   var fileContext = SP.ClientContext.get_current();

   var site = fileContext.get_site();
   fileContext.load(site);

   fileContext.executeQueryAsync(function() {
       var relUrl = attachment.Url.replace(_spPageContextInfo.siteAbsoluteUrl, '');
    
       var file = fileContext.get_web().getFileByServerRelativeUrl(relUrl);

       fileContext.load(file, 'ListItemAllFields');
    
       fileContext.executeQueryAsync(
           function () {
               var listItem = file.get_listItemAllFields(); 
           },
           function (sender, args) {
               console.log(args.get_message()); //errorhandling
           }
       );
   }, function(sender, args) {
       console.log(args.get_message());
   });  
}

this is not a permissions thing as I can take the urls of the documents being selected and open them fine from the browser. I have noticed, that I can't seem to hit the client.svc service on the site in question when taking the url for the request from the request object.

I am busy writing some javascript to take a list of selected documents and do some processing on a list with each document in Office365. I am getting a strange error when the code tries to load the document from the absolute URL. The document is guaranteed to be in the same SP.Web that the JS is in.

The error is

Value does not fall within the expected range.

Below is the JS I have:

function GetFile(attachment, item) {
   var fileContext = SP.ClientContext.get_current();

   var site = fileContext.get_site();
   fileContext.load(site);

   fileContext.executeQueryAsync(function() {
       var relUrl = attachment.Url.replace(_spPageContextInfo.siteAbsoluteUrl, '');
    
       var file = fileContext.get_web().getFileByServerRelativeUrl(relUrl);

       fileContext.load(file, 'ListItemAllFields');
    
       fileContext.executeQueryAsync(
           function () {
               var listItem = file.get_listItemAllFields(); 
           },
           function (sender, args) {
               console.log(args.get_message()); //errorhandling
           }
       );
   }, function(sender, args) {
       console.log(args.get_message());
   });  
}

This is not a permissions thing as I can take the url of the documents being selected and open them fine from the browser. 

I have noticed, that I can't seem to hit the client.svc service on the site in question when taking the url for the request from the request object.

Source Link
MrThirsty
  • 391
  • 8
  • 17

Javascript always failing

I am busy writing some javascript to take a list of selected documents and do some processing on a list with each document in Office365. I am getting a strange error when the code tries to load the document from the absolute URL. the document is guaranteed to be in the same SP.Web that the JS is in.

The error is "Value does not fall within the expected range."

Below is the JS I have:

function GetFile(attachment, item) {
   var fileContext = SP.ClientContext.get_current();

   var site = fileContext.get_site();
   fileContext.load(site);

   fileContext.executeQueryAsync(function() {
       var relUrl = attachment.Url.replace(_spPageContextInfo.siteAbsoluteUrl, '');
    
       var file = fileContext.get_web().getFileByServerRelativeUrl(relUrl);

       fileContext.load(file, 'ListItemAllFields');
    
       fileContext.executeQueryAsync(
           function () {
               var listItem = file.get_listItemAllFields(); 
           },
           function (sender, args) {
               console.log(args.get_message()); //errorhandling
           }
       );
   }, function(sender, args) {
       console.log(args.get_message());
   });  
}

this is not a permissions thing as I can take the urls of the documents being selected and open them fine from the browser. I have noticed, that I can't seem to hit the client.svc service on the site in question when taking the url for the request from the request object.