I use SharePoint Online and working in Visual Studio with SharePoint hosted app
I need to get list id and the id of the SELECTED item in the list
And i use a ribbon button to show a dialog and want the id to show in it
This is the code I am using:
var clientContext, hostweburl, parentContext, parentWeb, listItems;
clientContext = new SP.ClientContext.get_current();
hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
parentContext = new SP.AppContextSite(clientContext, hostweburl);
parentWeb = parentContext.get_web();
listItems = parentWeb.get_lists().getByTitle("RibbonTestSimon").getItems("");
$(document).ready(function () {
clientContext.load(listItems);
clientContext.executeQueryAsync(OnSuccess, OnFail);
});
function OnSuccess() {
var listString = "";
var listEnumerator = listItems.getEnumerator();
while (listEnumerator.moveNext()) {
var currentItem = listEnumerator.get_current();
listString += "<br/> " + currentItem.get_item('Title');
}
$('#divAllaItems').html(listString);
}
function OnFail() {
alert("Error");
}
function getQueryStringParameter(paramToRetrieve) {
var params =
document.URL.split("?")[1].split("&");
var strParams = "";
for (var i = 0; i < params.length; i = i + 1) {
var singleParam = params[i].split("=");
if (singleParam[0] == paramToRetrieve)
return singleParam[1];
}
}
This is the code for the ribbon button in this code i have the code that open a dialog box can that be the reason why it isnt work
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction Id="31f85d51-7911-4be4-b56e-0a165adcad5e.RibbonTest"
RegistrationType="List"
RegistrationId="100"
Location="CommandUI.Ribbon"
Sequence="10001"
Title="RibbonTest"
HostWebDialog="TRUE"
HostWebDialogWidth="480"
HostWebDialogHeight="240">
<CommandUIExtension>
<!--
Update the UI definitions below with the controls and the command actions
that you want to enable for the custom action.
-->
<CommandUIDefinitions>
<CommandUIDefinition Location="Ribbon.ListItem.Actions.Controls._children">
<Button Id="Ribbon.ListItem.Actions.RibbonTestButton"
Alt="RibbonTest"
Sequence="100"
Command="Invoke_RibbonTestButtonRequest"
LabelText="RibbonTest"
TemplateAlias="o1"
Image32by32=/>
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler
Command="Invoke_RibbonTestButtonRequest"
CommandAction="~appWebUrl/Pages/Default.aspx?{StandardTokens}&SPListItemId={SelectedItemId}&SPListId={SelectedListId}" />
</CommandUIHandlers>
</CommandUIExtension >