This topic contains 12 replies, has 0 voices, and was last updated by realchalliday 7 years, 8 months ago.
-
AuthorPosts
-
October 11, 2016 at 1:46 pm #1703
karennHello all,
Having a problem adding another filter to a saved search in SuiteScript 2.0.
We have a saved searched and now I want to use that saved search in a Portlet script. Okay using the search no problem. My problem comes in where I want to add a date filter to the search to be used in the script. Every time I would get an error. Could not figure out what the error was all about. I changed to filter on salesrep. Well no error but the filter is ignored. I am finding very little information on adding a filter to a saved search in 2.0.
Here is the code. You can see both the latest date and salesrep filter attempts. I have tried many operators without success. Search is a transaction search.
var mySearch = search.load({id: ‘customsearch1193′});
var dateone = format.parse({
value: ’10/01/2016′,
type: format.Type.DATE
});
var datetwo = format.parse({
value: ’10/10/2016’,
type: format.Type.DATE
});
//mySearch.filters.push(search.createFilter( {name: ‘createddate’, operator: search.Operator.BETWEEN, values:[dateone,datetwo]} ));
mySearch.filters.push(search.createFilter( {name: ‘salesrep’, operator: search.Operator.IS, values:[‘reps name here’]} ));
mySearch.save();
mySearch.run().each(function(result) {
do stuff……
return true;
});
So how do you add a filter to a saved search???
Thanks,
Karen
This is a cached copy. Click here to see the original post. -
October 11, 2016 at 2:14 pm #1704
MChammaTXDoes your saved search already contain filters in the saved search? I’d be curious to see whether you need to initialize the filter property first if it doesn’t have any filters (it may be null).
Something like
Code:
search.load({id: ‘customsearch1193’, filters:[]})
Also you wrote reps name here as the sales rep filter value. Are you writing the name or are you using the internal id? -
October 11, 2016 at 2:23 pm #1705
karennIt has filters already in the saved search
-
October 11, 2016 at 2:27 pm #1706
david.smithI have not tried this so I’m not sure. I typically don’t load a saved search into code. You would think what you have would work. Although I’m not sure the salesrep filter is correct.
Maybe try something like this (not tested)
Code:
var mySearch = search.load({id: ‘customsearch1193’});
var filters = mySearch.filterExpression;
filters.push(‘and’,[‘createddate’,’between’,dateone,datetwo]);
mySearch.filters = filters;
mySearch.run().each(function(result) {
do stuff……
return true;
});
Why are you doing the save?mySearch.save();
https://chrome.google.com/webstore/d…epdmfaihdokglp
-
October 11, 2016 at 2:29 pm #1707
erictgrubaughYour syntax for adding the filter is just fine, but you are using the wrong search operator on your filter. You need to use the `ANYOF` operator, not the `IS` operator. `salesrep` is a Select field, and the only valid operators for Select fields are `ANYOF` or `NONEOF`.
See the Help page titled “Search Operators” for a table of which operators are valid for which field types.
-
October 11, 2016 at 9:54 pm #1708
ironside..have used this syntax successfully adding more filters to a loaded search (I prefer the readability of the search filter syntax):
PHP Code:
mySearch.filterExpression = mySearch.filterExpression.concat(“AND”, [
[‘entity’, ‘is’, customerId], ‘OR’, [‘customer.parent’, ‘is’, customerId]
]) -
October 11, 2016 at 10:00 pm #1709
ironsideI used to believe this too Eric, but the ‘is’ operator seems to be working (see my example against entity and customer.parent). That said, I still agree it’s safer to use ANYOF
Originally posted by erictgrubaugh
View Post
Your syntax for adding the filter is just fine, but you are using the wrong search operator on your filter. You need to use the `ANYOF` operator, not the `IS` operator. `salesrep` is a Select field, and the only valid operators for Select fields are `ANYOF` or `NONEOF`.
See the Help page titled “Search Operators” for a table of which operators are valid for which field types.
erictgrubaugh replied on 10/11/2016, 10:25 PM: Could be that SuiteScript processes the IS correctly for single arguments, but not Arrays.
-
October 12, 2016 at 6:25 am #1710
karennHi All,
No joy with all the suggestions.
Forgetting the salesrep where we tried IS and ANYOF and nothing worked, that was just to see if I could get something to work, what we really need is to add a date filter. Also the save was just something to try out of desperation. Forgot it was even still there.
Bottom line, we need to add a date filter, dateone and datetwo, to a saved search in javascript suitescript portlet script. Cant seem to get it to recognize the additional filter.
Thanks all!!
Karen
-
October 12, 2016 at 8:16 am #1711
JacksonPPossibly the filter you need, it worked for me loading a search.
Code:
mySearch.filters.push(search.createFilter({
name: ‘datecreated’,
operator: ‘within’,
values: [“10/1/2016 12:00 am”, “10/10/2016 11:59 pm”]
}));
(is ‘createddate’ a field you created?) -
October 12, 2016 at 9:21 am #1712
david.smithWhat Jackson said.
Also, if the date range is constant you could just add that to your saved search as criteria instead of trying to load and calculate it in the script.
Code:
var customrecord_subSearchObj = search.create({
type: “customrecord_sub”,
filters: [
[“custrecord_test”,”is”,”F”],
“AND”,
[“isinactive”,”is”,”F”],
“AND”,
[“custrecord_process_date”,”onorafter”,”6/1/2016 12:00 am”],
“AND”,
[“created”,”within”,”daysago20″,”daysago10″]
],
columns: [
search.createColumn({
name: “custrecord_client”,
summary: “GROUP”
}),
…
]
});
customrecord_subSearchObj.run().each(function(result){
return true;
}); -
October 12, 2016 at 9:56 am #1713
al3xicondavid.smith – I thought the “daysagoxxx” were deprecated, are there similar ones you’d recommend using in their place?
david.smith replied on 10/12/2016, 10:49 AM: Interesting. You are correct it’s listed as being depreciated but that’s what NS still uses in their saved searches. I’m sure it will continue to work for quite some time.
You could always try the Date As Of Selectors: https://netsuite.custhelp.com/app/an…ail/a_id/40228
Or, I guess you could use a formula but that takes longer to execute.
["formulanumeric: case when ({created} > {today}-17 AND {created} < {today}-15) then 1 else 0 end","equalto","1"]
-
October 12, 2016 at 10:01 am #1714
karennWe have success!!!!!!!! Thank you JacksonP!!!! Not sure how we did not try that combo but it is working!!!
You guys are all awesome!! Thanks so much everyone. On to the next problem
Thanks!
-
February 24, 2017 at 4:53 pm #1715
realchallidayJaksonP’s method worked for me too.
Code:
var mySearchObj = search.load({
type: ‘transaction’,
id: ‘customsearch_that_i_have’,
});
mySearchObj.filters.push(search.createFilter({
name : ‘custbody_invoiceduedate’,
operator : search.Operator.ONORBEFORE,
values : [‘today’]
}));
var searchResult = mySearchObj.run().getRange({
start: 0,
end: 999
}); -
AuthorPosts
You must be logged in to reply to this topic.