0

I have created a SharePoint Addin following this step by step Microsoft guide and it works fine.

Now I would like to add some javascript CSOM to my "internal" list and I wrote the following code:

function createListItem() {
    var siteUrl = 'https://mysharepointaddress.sharepoint.com/sites/app';
    var clientContext = new SP.ClientContext(siteUrl);
    var oList = clientContext.get_web().get_lists().getByTitle('New Employees in Seattle');

    var itemCreateInfo = new SP.ListItemCreationInformation();
    this.oListItem = oList.addItem(itemCreateInfo);

    oListItem.set_item('Title', 'My New Item!');

    oListItem.update();

    clientContext.load(oListItem);

    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

The list name cannot be found. I would try with .getById(guid) but i don't know how to find the guid of this list.

Tested on a normal list, created via Site Content - Add an app, and the code works fine.

Any advice is much appreciated, thanks in advance!

1

To add item to app list, please replace the code below

var clientContext = new SP.ClientContext(siteUrl);

with

var clientContext = new SP.ClientContext.get_current();

Example: https://github.com/OfficeDev/SharePoint-Add-in-JSOM-BasicDataOperations

0

To get the list Id :

  1. Go to your target list in Sharepoint
  2. From the ribbon select List the click on List settings.
  3. You will find it in the URL : List=%7B92BFE60B-147A-49CD-8C86-38CD90987235%7D
  4. Take the Id between %7B and %7D, so the Guid is 92BFE60B-147A-49CD-8C86-38CD90987235

Just to be sure that you get the good Title of your list, try to get it from URL of your list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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