does anyone know why in a programmatically-run sav...
# suitescript
u
does anyone know why in a programmatically-run saved search, a filter criteria fetched from an existing saved search doesn't work? for context, I pulled out the filter for a Transaction-type Saved Search that returns Sales Invoices within a date range for a specific customer (
customermain.entityid
) using 
search.filterExpression
, yet when creating a saved search in SS2, adding that filter returns an error saying that it isn't a valid search criteria. here's the code snippet of the search I made. maybe I missed something?
Copy code
var stateSearch = search.create({
			type: search.Type.TRANSACTION,
          	columns: [
              		{ name: 'ordertype' },
              		{ name: "mainline" },
              		{ name: "trandate" },
              		{ name: "tranid" },
              		{ name: "duedate" },
              		{ name: "amount" },
              		{ name: "type" }
            ],
		    filters: [{
              			name: "type",
						operator: "anyof",
						values: ["CustInvc"]
					 },
          			 {
              			name: "mainline",
						operator: "is",
						values: ['T']
					 },
          			 {
                        name: "customermain.entityid",
						operator: "is",
						values: ["Some Guy"]
					 },
          			 {
              			name: "trandate",
						operator: "within",
						values: [startDateField, todayDateField]
					 }]
		});
b
there are 2 types of ways to do filters
filter expressions and filter objects
you are using filter objects, that array of objects you are using for the filter is actually converted using search.createFilter
customermain.entityid
is how you would specify a joined search filter in a filter expression, it wont work in a filter object
1
u
thanks @battk. changing the syntax of my filters based on what you linked did the trick for me. i did some more googling to figure out how to translate the format for date ranges, but this code worked for me.
Copy code
filters: [
        		["type", search.Operator.ANYOF, "CustInvc"],
        		"and",
            	["mainline", <http://search.Operator.IS|search.Operator.IS>, "T"],
            	"and",
            	["customermain.entityid",  <http://search.Operator.IS|search.Operator.IS>, "Some Guy"],
            	"and",
            	["trandate",  search.Operator.ONORAFTER, startDateField],
            	"and",
            	["trandate",  search.Operator.BEFORE, todayDateField]
    	  ]
Thanks again.