I am trying to set up a simple subscription tool where users can subscribe to or unsubscribe from various distribution list. The idea is that you select a user through a people picker ('subuser'), select a list ('sublist') and click either subscribe (so you are added to the selected list) or unsubscribe (so you are deleted from the selected list). I have succeeded with the subscribe part, but got stuck at unsubscribe. I know how to delete an item from a list, but to do that I need to have an item's ID (or is there any other way?). This is the part of my code that I want to use to get the ID for the item that includes a user selected via the people picker, but itemID is undefined:
function removeUser()
{
var clientContext = new SP.ClientContext(siteurl);
var value1 = document.getElementById('subuser').value;
var value2 = document.querySelector('input[name="sublist"]:checked').value;
var queryLookup = "<Where><Eq><FieldRef Name='UserName' LookupId='TRUE' /><Value Type='Lookup'>"+ value1 +"</Value></Eq></Where>";
var itemID="";
$().SPServices({
operation: "GetListItems",
async: false,
listName: value2,
CAMLViewFields: "<ViewFields><FieldRef Name='ID'/></ViewFields>",
CAMLQuery: queryLookup,
completefunc: function(xData,Status) {
itemID = $(xData.responseXML.xml).find("z\\:row").attr("ows_ID");
}
});
}
SPServices can be replaced by any other working solution. Thank you for any suggestions.