Creating AdvancedCriteria With JSNI

I need to create AdvancedCriteria in order to do filter data over a date range. I would like to generate this manually rather than use filter builder or something along those lines, since I have created my own search feature, but I heard this must be done using JSNI.

public static native JavaScriptObject getDateRangeJSObject(String field, Date from, Date to) /*-{
		var advancedCriteria = {
			_constructor:"AdvancedCriteria",
			operator:"and",
			criteria:[
			{ fieldName: field, operator:"greaterOrEqual", value: from },
			{operator: "and", criteria:[
				{ fieldName: field, operator:"lessOrEqual", value: to }
				]
			}
			]
		}
		
		return advancedCriteria;
	}-*/;

which takes the field name to search (from the list grid) and two date objects.

I then use

AdvancedCriteria ac = new AdvancedCriteria(SearchWidget.getDateRangeJSObject("week_of", from_date, to_date));
wr_grid.fetchData(ac);

To create a new AdvancedCriteria. Am I doing it wrong? When I do the search, the grid shows ‘No items to view’ and the hosted mode shell displays some 'Malformed JSNI reference ‘constructor’ expect subsequent failures" notices (although I already had some to start with - more are created).

You have a incorrect (2nd one) nested operator: “and”

I believe the following JSNI declaration will work. Note that your previous declaration had a nested partial AdvancedCriteria JSO object declared:
{ fieldName: field…
{operator: “and”, criteria:[
{fieldName: field…

Instead, try this, which does not have a nested operator/criteria JSObject:

var advancedCriteria = {
_constructor:“AdvancedCriteria”,
operator:“and”,
criteria:[
{ fieldName: field, operator:“greaterOrEqual”, value: from },
{ fieldName: field, operator:“lessOrEqual”, value: to }
]
}