I use sharepoint online and this is going to be an app
I need to loop through an array to get all items that are selected in a list, now i can only get one item but i need to get more items at once to do that i have .split(',') on this row:
itemId = decodeURIComponent(getQueryStringParameter("SPListItemId")).split(',');
and i need an loop to go through all items that are selected
var i, array;
for (i = 0; i > array.length; i++)
{
}
and this is all code:
'use strict';
var clientContext, hostweburl, parentContext, parentWeb, selectedItem, itemId, listId;
clientContext = new SP.ClientContext.get_current();
hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
listId = decodeURIComponent(getQueryStringParameter("SPListId"));
itemId = decodeURIComponent(getQueryStringParameter("SPListItemId")).split(',');
parentContext = new SP.AppContextSite(clientContext, hostweburl);
parentWeb = parentContext.get_web();
selectedItem = parentWeb.get_lists().getById(listId).getItemById(itemId);
$(document).ready(function () {
clientContext.load(selectedItem);
clientContext.executeQueryAsync(OnSuccess, OnFail);
});
function OnSuccess() {
var i, array;
for (i = 0; i > array.length; i++)
{
}
$("#Blue").click(function () {
selectedItem.set_item('Color', 'Blue');
selectedItem.update();
clientContext.load(selectedItem);
clientContext.executeQueryAsync(function () { window.parent.postMessage('CloseCustomActionDialogRefresh', '*'); }, function (sender, args) { alert('Error:' + args.get_message()); });
});
$("#Green").click(function () {
selectedItem.set_item('Color', 'Green');
selectedItem.update();
clientContext.load(selectedItem);
clientContext.executeQueryAsync(function () { window.parent.postMessage('CloseCustomActionDialogRefresh', '*'); }, function (sender, args) { alert('Error:' + args.get_message()); });
});
$("#Red").click(function () {
selectedItem.set_item('Color', 'Red');
selectedItem.update();
clientContext.load(selectedItem);
clientContext.executeQueryAsync(function () { window.parent.postMessage('CloseCustomActionDialogRefresh', '*'); }, function (sender, args) { alert('Error:' + args.get_message()); });
});
$("#Transparent").click(function () {
selectedItem.set_item('Color', 'No Color');
selectedItem.update();
clientContext.load(selectedItem);
clientContext.executeQueryAsync(function () { window.parent.postMessage('CloseCustomActionDialogRefresh', '*'); }, function (sender, args) { alert('Error:' + args.get_message()); });
});
}
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];
}
}
NOTE i can't use SP.ListOperation.Selection.getSelectedItems(clientContext); because i will not have my code on the host web just on the app web and then this will not work