List filter with var

Hi, having some trouble filtering a list using values from dropdown fields. My code is below, it works when I hardcode the filter values in, and the "alert" brings back the correct text from the dropdown. So I am guessing either my syntax is wrong for passing the variable to the CAML or the variable that is being passed needs to be of a different type?? The List columns being filtered against are Choice (on dropdown one checkbox).

Thanks,

fd.spRendered(function() {
var dt = fd.control('SPDataTable5');

dt.ready().then(function() {
    filterDT();
});

 fd.field('Sect').$on('change', function(value) {
    filterDT();
});

fd.field('Status').$on('change', function() {
    filterDT();
    });


function filterDT(){
	var sectorID = fd.field('Sect').value;
	var statusID = fd.field('Status').value;
    var filter = "<And>";
	alert(statusID);
    filter += "<Contains><FieldRef Name='Sector'/><Value Type='MultiChoice'> + sectorID + </Value></Contains>";
    filter += "<Contains><FieldRef Name='Project_x0020_Status'/><Value Type='Choice'> + statusID + </Value></Contains>";
    filter += "</And>";
    dt.filter = filter;
	//dt.filter = "<Eq><FieldRef Name='Project_x0020_Status'/><Value Type='Choice'> + statusID + </Value></Eq>" ;
    dt.refresh();
} });

Try this
filter += " " + sectorID + " ";
filter += " " + statusID + " ";

The text isn’t showing up properly, perhaps because I am on a mobile device. But it looks like you need to close your quotes after then reopen after adding your variable. Hopefully that makes sense.

2 Likes

Yes, you're right I think. I'll try this when back at work, definitely needed a fresh pair of eyes there, thanks.