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
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>
-
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.– BetsenCommented Dec 3, 2013 at 11:57 -
-
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– BetsenCommented 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
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());
}
-
what is
siteUrl
in this case? it seems that this value has never been set... Commented Oct 6, 2016 at 10:12