Hi Guys
I am needing help with filtering a SharePoint list with JavaScript. The scenario is that I have a drop down with values that correspond to columns on a list. I would like to filter on region and state. its fine if I have a value for region and for state but when either is say an empty string or null I cant then do a filter on either of the columns. I think my logic is flawed. I was wandering if somebody could help with this.
1. These are my filters in html
<div> state:<select id="state"><option value="Production Geoscience">Production Geoscience</option><option value="Wells">Wells</option><option value="PetroPhysics">PetroPhysics</option><option value="GeoChem">GeoChem</option></select> region:<select id="region"><option value="Americas">Americas</option><option value="Asia">Asia</option><option value="Global">Global</option><option value="Europe">Europe</option></select><br/><table id="ContactsList"><thead><tr><th>Name</th><th>Region</th><th>Domain</th><th>Email Me</th></tr></thead><tbody id="profilePictures"></tbody></table></div>
2. And then this retrieves their userProfile information
var gtLogName = function getUserLoginName () {
state = "";
region = "";
console.log(region);
console.log(state);
$("#profilePictures").html("");
if(state!=""&®ion!=""){
// execute AJAX request
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('experts')/items?$select=supportId&$filter=Region eq'" +region+ "' and
Domain eq '" +state+"'",
type: "GET",
headers: { "ACCEPT": "application/json;odata=verbose" },
success: function (data) {
console.log(data);
var dataRes = data.d.results;
var resultid;
for (i=0; i< data.d.results.length; i++) {
resultid = dataRes[i].supportId;
getUsAcc(resultid);
console.log(region);
}
},
error: function () {
alert("Failed to get details");
}
});
} //end if
}
$(function(){
$("#profilePictures").ready(gtLogName());
$("#state").change(function(){
$("#profilePictures").ready(gtLogName());
});
$("#region").change(function(){
$("#profilePictures").ready(gtLogName());
});
});
So if I use the dropdown values when the region and the state have values it works. but when one of the values is null I would expect it to just pull all the values for that particular one.