When I completely OCD out on a problem and finally get an answer, I want two things. First, I don’t ever want to waste time on it again. And second, I don’t want anyone else wasting time on it either. If you ever need to write a search in SuiteScript that involves a join, please read this first!
I needed a popup that would search through a custom record type based on various filters.
So the code under the hood required the following (not that this really matters, It’s just for the curious).
- An inline HTML button to launch this popup.
- A client script to fetch the HTML from a file in the file cabinet to render this page.
- A Restlet that gets called when the user clicks search to deliver the results.
So now I’m only going to focus on the Restlet that delivers the results in this popup. And I’m going to give you the basics of how I coded my filter for two of the fields on the screen, owner and vendor. They don’t work the same, and dang was this frustrating.
Here are the definitions for owner and vendor in my Software Agreements custom record type.
Notice, both are List/Record types. However, they reference different lists. This was the rub! You’d expect them to work the same, but they DID NOT.
I kept getting an error on the search filter definition at the time the search executed. It was telling me I had an invalid search expression. When I omitted the vendor criteria, it worked. When I added back the vendor criteria, it failed. Here’s the code after it was working.
Here’s the dirty little secret. There’s this thing called the record type’s Valid Search Filters table. What the heck? companyname is in this table for customers, but not in it for vendors. In order to search for companyname in the vendor’s table, I needed to swap companyname for entityid.
I worked with a wonderful support rep from NetSuite name Fe. I asked her, “How can I prevent this from happening again?” Here is what she told me.
To make sure that all search filter IDs are valid:
- Open the SuiteScript Records Browser(SuiteAnswers ID: 74610 – The SuiteScript Records Browser).
- Navigate to the record type being searched.
- kindly go to Vendor
- Locate the Search Filters table and check if all nlobjSearchFilter field IDs used in your code are found within the table.
You can also refer to SuiteAnswers ID: 45294 – SuiteScript Error SSS_INVALID_SRCH_FILTER
Hopefully, this saves you the headache I have right now after resolving this issue. And many thanks to Fe for her excellent help.