locked
Call SharePoint web services via JavaScript from SharePoint page? RRS feed

  • Question

  • I read that SharePoint online prohibits the use of custom code; for example, I can't upload a web page that makes calls to the SharePoint API.

    Is it possible to work around this limitation by uploading custom SharePoint pages that use JavaScript to make calls to SharePoint through its web service API instead? I might use that technique to iterate through some SharePoint lists and generate HTML on the fly.

    Not sure this is a good idea, just wanted to know how to work around SharePoint Online's restrictions.

    Thanks!

    McGeeky
    Monday, April 6, 2009 10:41 PM

Answers

  • Hi McGeeky,

    Yes, your idea to use JavaScript to work around the custom code limitation will work. The nice thing about using Javascript in this way is it will always run in the context of the current user so the web service call will run as the current user. Thus ensuring they have permission to view the data. You can do the same thing using Silverlight as well. I personally prefer the Silverlight option.
    Tuesday, April 7, 2009 12:03 AM

All replies

  • Hi McGeeky,

    Yes, your idea to use JavaScript to work around the custom code limitation will work. The nice thing about using Javascript in this way is it will always run in the context of the current user so the web service call will run as the current user. Thus ensuring they have permission to view the data. You can do the same thing using Silverlight as well. I personally prefer the Silverlight option.
    Tuesday, April 7, 2009 12:03 AM
  • Good day,

    I would like to Update a document library with javascript.

    Please share code as i'm struggling & have no clue

    Regards
    Thursday, January 7, 2010 8:18 AM
  • Hi Ismailc. In what way you would like to update a document library? Let me know and I will look to provide some example JavaScript.

    Regards,

    Myles
    Catch me on Twitter
    Thursday, January 7, 2010 6:07 PM
  • Hi, Thanks for replying - I managed to get an example working in javascript

    The problem i now have is that I can't seem to update the document library (list) filter on Title, it needs the ID.
    My 3rd party does not have the ID & only the Title - please Help on how to update filetring on Title.

    I removed ID & fil;tered on Title only but does not work

    [code]

    function SaveListItem()
    {
    var soapRequest = '<?xml version="1.0" encoding="utf-8"?>' +
    '<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">' +
    ' <soap12:Body>'+
    ' <UpdateListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">'+
    ' <listName>Vendor Request</listName>'+
    ' <updates>'+
    '<Batch OnError="Continue">'+
    ' <Method ID="1" Cmd="Update">'+
    ' <Field Name="ID">772</Field>'+
    ' <Field Name="FSObjType">1</Field>'+
    ' <Field Name="BaseName">70002</Field>'+
    ' <Field Name="Title">70002</Field>'+
    ' <Field Name="Vendor0">TestDataNEW</Field>'+
    ' </Method>'+
    '</Batch>'+
    ' </updates>'+
    ' </UpdateListItems>'+
    ' </soap12:Body>'+
    '</soap12:Envelope>';

    xmlHttp=new XMLHttpRequest();
    xmlHttp.open('post', 'http://srv08-za143/workspace/departments/masterfiles/_vti_bin/Lists.asmx', false,null,null);
    xmlHttp.setRequestHeader('Content-Type','application/soap+xml; charset=utf-8');

    xmlHttp.send(soapRequest);

     

    }

    [/code]

     

    Monday, January 11, 2010 8:05 AM
  • Hi Ismailc. That's great you figured out the JavaScript to call the UpdateListItems SharePoint Online web service!

    I understand that you have run in to an issue in that you only have the item Title, not the ID which is required by UpdateListItems.

    I would recommend that you look up the ID first using the GetListItems method http://msdn.microsoft.com/en-us/library/lists.lists.getlistitems.aspx filtering on Title. You can then extract the ID that is returned (assuming there is a match) and feed that in to your UpdateListItems web service call.

    Hope this helps.

    Regards,

    Myles
    Catch me on Twitter
    Monday, January 11, 2010 9:49 AM
  • Hi, do you perhaps have example for me?

    I think i got it going by specifying the ID ""

    batch = batch + " <Method ID='1' Cmd='Update'>"
    batch = batch + "  <Field Name='ID'></Field>"
    batch = batch + "  <Field Name='FSObjType'>1</Field>"
    batch = batch + "  <Field Name='BaseName'>70002</Field>"
    batch = batch + "  <Field Name='Title'>70002</Field>"
    batch = batch + "  <Field Name='Vendor0'>999999</Field>"

    It updates the correct one- is this by chance - please let me know

    Regards

    Monday, January 11, 2010 10:26 AM