Tip 20: How can I use a search on Document(file) type in Netsuite SuiteScript (1.0 & 2.0)

Hello Friend,

Its always advised to avoid using saved searches  in scripting as there may be a chance of getting deleted either knowingly/unknowingly.

But there are certain searches which are not included in Search.Type like below example:

While working on a requirement, I realized to add a search on File. As I suggested above I always prefer to use search created in script rather than using a saved search.

But unfortunately I didn’t find any Search.Type for File/Document Type.

So below code was showing error Type Document is not a Valid type in Search.

var mySearch = search.create({
                type: Search.Type.DOCUMENT,
                filters : myFilters,
                columns : myColumns
            });

 

Then I checked in Saved Search and Document type is available there.

Not sure why Netsuite has that difference in Search.Type and Saved Search Type.

Then I created a saved search using Document type and loaded that search in my script as I have no other option.

saved_seach
Fig 1 – Saved Search On Document Record

I recommend to use word like “(Used By Script)” or “(DO NOT DELETE)” in saved search name, so that if somebody will see that saved search, he will be able to understand, this saved search is used for some script. So risk of getting deleted will be reduced to somewhat.

So, here a simple suggestion to all who has similar issues:

If something is not happening using search.create(), try creating saved search on same search type and use search.load() and use that as search.load() doesn’t need any type parameter.

           //Load Saved Search created already with selected id as filter
            var mySearch = search.load({
                id: ‘customsearch_search_file’
            });

I have used SuietScript 2.0 in my sample code. You can refer to SuiteScript 1.0 accordingly if you need.

Hope that will help you.

Happy Coding 🙂

Thanks,

Asha

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s