0

my structure in SharePoint 2013 is something like this:

  • RootSiteCollection
    • RootWebSite
      • ListA
    • SubSiteCollection
      • SubWebSite
        • Page

And now I need to create an item in the 'ListA'

What I tried:

function Report(Data) {

var Context = new SP.ClientContext.get_current();
var Site = Context.get_site();
var Website = Site.get_rootWeb();
var List = Website.get_lists().getByTitle('ListA');

var ItemCreation = new SP.ListItemCreationInformation();

var TimeCode = (new Date).getTime();

var Item = List.addItem(ItemCreation);
Item.set_item('FileLeafRef','Test_'+TimeCode);
Item.set_item('Title','Test_'+TimeCode);
Item.set_item('Data',Data);

Item.update();
Context.load(Item);
Context.executeQueryAsync(onFolderCreationSuccess, onFolderCreationFail);

function onFolderCreationSuccess() {

}

function onFolderCreationFail(sender, args) {
    alert('Error:' + args.get_message());
}

}

My Problem: The code tries to find the ListA in the SubSiteCollection. But I thought "get_rootWeb()" sound´s like real root. What is the trick and how can I create an item in the ListA from my Page?

1 Answers1

0

SharePoint does not allow site collections to be created within site collections, so you may be misunderstanding the relationship between your sites.

If what you've labeled as "SubSiteCollection" exists and is different from "RootSiteCollection," then the sites exist within different site collections altogether, and you will not be able to use the JavaScript client object model to share list data between them.

You can, however, use the SharePoint REST web services to retrieve and modify data across site collections.

Thriggle
  • 7,009
  • 2
  • 26
  • 37
  • You are right..SiteCollections are non hierarchical..sorry..the only way is the REST? – user1957700 Jul 28 '15 at 15:12
  • You can use the REST services (https://msdn.microsoft.com/en-us/library/office/fp142380.aspx) or you can also use the Lists web service: https://msdn.microsoft.com/en-us/library/office/websvclists.aspx (which you'd need to invoke using XmlHttpRequest or a comparable AJAX wrapper, such as those provided by the jQuery library). Another alternative is to embed your JavaScript on a page in the source site collection, and show that page in the second site collection using a page viewer or iframe. – Thriggle Jul 28 '15 at 15:26