Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

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>
share|improve this answer
    
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 Dec 3 '13 at 11:57
    
You could add this in Default.aspx of your App –  Falak Mahmood Dec 3 '13 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 Dec 3 '13 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/… –  Falak Mahmood Dec 3 '13 at 22:16
add comment

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());
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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