2

Currently my app reads the list items and shows in an app part(visible to all site visitors). Now we would like to extent the functionality. If the user has contribute permission to the list(site), there should be a link in the app part where they can click to add a new list item. How may I achieve it? and what is the best way to do it?

2 Answers 2

1

You can use XsltListViewWebPart which provide more OOTB look and feel while adding to the list. Provide the ListUrl property with the list you want to add items to

<WebPartPages:WebPartZone runat="server" FrameType="TitleBarOnly" ID="full" Title="loc:full">
        <WebPartPages:XsltListViewWebPart runat="server"
            ListUrl="Lists/CustomDocumentLibrary"
            IsIncluded="True"
            JsLink="clientTemplate.js"
            NoDefaultStyle="TRUE"
            PageType="PAGE_NORMALVIEW"
            Default="False"
            ViewContentTypeId="0x">
        </WebPartPages:XsltListViewWebPart>
    </WebPartPages:WebPartZone>
4
  • Thanks Falak for your quick reponse: as I'm a novice, and would like to know, how can I add XsltListViewWebPart in an app. I know you might not have time to explain everything, but could you please point me to a sample-app/tutorial or any other related information.
    – Betsen
    Commented Dec 3, 2013 at 11:57
  • You could add this in Default.aspx of your App Commented Dec 3, 2013 at 14:11
  • When i take list from HostUrl, how do I get the value ListUrl? Googled it and found examples of list in the appweb, but not host. Thanks in advance
    – Betsen
    Commented Dec 3, 2013 at 18:08
  • You can ListUrl for AppWeb as well as Host web. See some examples at Chris o Brien's blog: sharepointnutsandbolts.com/2013/08/… Commented Dec 3, 2013 at 22:16
0

Another easy way to acheive adding new list item to ShareLoint list using Javascript in APP 2013.

Write the following code in your App.js and call "btnSubmit_CreateListItem" event in ADD button click:

function btnSubmit_CreateListItem() {

    //siteUrl will be your host web url.

    //app web
    var clientContext = new SP.ClientContext.get_current();

    //host web
    var parentCtx = new SP.AppContextSite(clientContext, siteUrl);
    var oList = parentCtx.get_web().get_lists().getByTitle('ListName');

    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)

    );
}


function onQuerySucceeded(sender, args) {
    alert('Item created: ' + oListItem.get_id());
}

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
1
  • what is siteUrl in this case? it seems that this value has never been set...
    – Snickbrack
    Commented Oct 6, 2016 at 10:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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