0

I cannot seem to find any information on the behaviour of lists added to a VS "App for SharePoint" project.

The process of adding a custom list is quite similar to what you would do in SP Designer.

When adding a List to your project, there is even the option to Show/Hide that particular list in the "Quick Launch".

However, when I deploy my simple app to the SP server and access it, the list I defined in the project is nowhere to be found (or so it seems).

I therefore wonder what the expected behaviour is for this or how one should go about to deploy a custom app that makes use of one or more custom lists.

EDIT

This question seems related to this one (if not completely the same) so I was a bit to quick to duplicate it here. Nonetheless, as I now understand, lists added to a VS App project will only be available in the "App Web".

So that makes me wonder, what If I want to use my app to add information to a SP website such that it will also be available/persisted outside the App itself?

Taking the common example of a TODO list App for Sharepoint and instead of using a pre-existing "Tasks" list, I add my own version to my App project.

How can I make that custom list accessible outside my app, or is that never a good idea?

What happens if I make updates to my app and re-deploy it? Will all my data be lost?

1

Here are a few points of considerations

  1. Apps are virtually a subsite complete with their site-settings and site-contents.
  2. Data stored in a list in the appweb is not persistant over multiple deployments.
  3. The hostweb and the appweb are virtually considered different domains.

what If I want to use my app to add information to a SP website such that it will also be available/persisted outside the App itself?

If you want to store persistant data, consider storing it in the host web -

You need to use SP.RequestExecutor.js to achive this. The typical structure of a function is something like the following.

    var url = appwebUrl +    
    "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('"+listName+
    "')/items?$select=Title,ID&@target='" + hostUrl + "'";


    var scriptbase = hostUrl + "/_layouts/15/";
    $.getScript(scriptbase + "SP.RequestExecutor.js", function () {

        var url =  appwebUrl +
                  "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('" + listName + "')/items?$select=Title,ID&@target='" + hostUrl + "'";


        var executor = new SP.RequestExecutor(appwebUrl);
        executor.executeAsync(
        {
            url:     url,
            method:  "POST",
            headers: { "Accept": "application/json; odata=verbose", "content-type": "application/json; odata=verbose"},
            success: function () {alert('success')},
            error:   function(){alert("error");
        }

How can I make that custom list accessible outside my app, or is that never a good idea?

AFAIK, there is no reason to do that, as you can always push updates to host web. In case you wanna display the app data in the hostweb consider implementing a Client Web Part

What happens if I make updates to my app and re-deploy it? Will all my data be lost?

All the data inside the appweb i.e. your app level lists and libraries, will be lost.

| improve this answer | |
  • Thanks for the useful comments. However, I'm still a bit confused. We were given an SP server but we cannot run code in on the it (which makes sense) so an SP App (with all the logic client side) is the only option. I now want to make an App to keep track of lab resources (Ordering, keeping stock, ...). I do not want to lose data when I push improvements to the app. I initially thought I could deploy the app together with any lists the app might need but as I understand now you should actually deploy the lists (as templates?) separately from the App such that they live in the host domain? – Kris Sep 14 '15 at 15:42
  • Many online SP resource talk about the App model but many forgo real world examples of how you can actually do useful stuff with it. I guess I am this still looking for "the way things ought to be done" here... – Kris Sep 14 '15 at 15:43
  • Just implement the ui and the business logic in the app - such as interfaces to create, add items, update item count, etc. If you want to store persistant data, then build a rest based crud structure which will enable you to do all the operations with the host app. Use app lists to just store the transient data such as configuration details etc. – Swayam Siddha Sep 15 '15 at 6:10
  • OK, then I am on the right track now! Thanks for all the feedback! – Kris Sep 15 '15 at 8:09

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.