I'm trying to copy specific field data from list items to properties in an object, which appears to be working, however, I have multiple rows of data and the function is pasting the same row every time into my array. I'm obviously missing something, but not sure what. Also, if there is a better way to do this I'm all ears! See code below...
function getListData(listName) {
dfd = $.Deferred();
parentId = GetUrlKeyValue("ID", false, location.href);
var context = SP.ClientContext.get_current();
var web = context.get_web();
context.load(web);
var list = web.get_lists().getByTitle(listName);
var caml = new SP.CamlQuery();
caml.set_viewXml('<View><Query><Where><Eq><FieldRef Name="LinkID" /><Value Type="Lookup">' + parentId + '</Value></Eq></Where></Query></View>');
listItems = list.getItems(caml);
context.load(listItems, "Include(ID, Current_x0020_Public_x0020_IP_x0, New_x0020_Public_x0020_IP_x0020_, New_x0020_Assigned_x0020_Public_, Disconnect_x0020_IP_x0020_Subnet)");
context.executeQueryAsync(function() {
var count = listItems.get_count();
var arraySubnet = [];
var PublicSubnet = { current: "", new: "", assigned: "" };
var listEnumerator = listItems.getEnumerator();
while (listEnumerator.moveNext()) {
listItem = listEnumerator.get_current();
id = listItem.get_item("ID");
currentSubnet = listItem.get_item('Current_x0020_Public_x0020_IP_x0');
newSubnetRequested = listItem.get_item('New_x0020_Public_x0020_IP_x0020_');
newAssignedSubnet = listItem.get_item('New_x0020_Assigned_x0020_Public_');
PublicSubnet.current = currentSubnet;
PublicSubnet.new = newSubnetRequested;
PublicSubnet.assigned = newAssignedSubnet;
arraySubnet.push(PublicSubnet);
} // End while
console.log(arraySubnet);
dfd.resolve();
}, function() {
dfd.reject();
});
return dfd.promise();
}
