How to search Custom Record in Netsuite Suite Script 2.0?

Hi All,

This is my 100th post so I want to post something important and which very hard to find.

We all know that Netsuite provide example code of search for native record or builtin record,
But if you try to search for custom record then script will throw error.
Previously Error message were very clean but now error messages are also becoming mess.

 So coming to point,

If we want to search built in record then use below code
var arrSearch = search.create({
                                                        type : search.Type.ITEM,
                                                        columns : yourColumns,
                                                        filters : yourFilters
                                                       
                                                    });

Now search.Type.ITEM can be changed by other record types and we can get data from that record easily using search.

If we want to search Custom Record:

Use below code for custom record search. I tried with Capital Letters , you can try with small letters and let me know if that is also working or now.

var dynamicSearch = search.create({
                                                type : 'CUSTOMRECORD_MYREC',
                                                columns : yourColumns,
                                                filters : yourFilters
                                               
                                            });

** CUSTOMRECORD_MYREC is my custom record's internal id(Record type).

Now How to get 1000 results?

Use below code and get 1000 results.

var dynamicSearchResults = dynamicSearch.run().getRange({
                                                                    start : 0,
                                                                    end : 1000
                                                                });
                 
I hope this blog will help you, Please comment below if you have any thoughts on this or any better idea .
Please do comment if you think above code is not working or where to use this code.

Thanks
Abhi        

Comments

  1. how to get more then 1000 records

    ReplyDelete
  2. if you are doing scripting in script 1.0 then result set can give 4000 results, nlapiSearchRecord can give you 1000 and in suite script 2.0 you can use getrange and use 1000 each time until finished.
    I personally use do...whole loop in Suite Script 1.0 to get all results till last result. I store internal ids in an array and use that array as "internalid none of array". This functionality need change if your search is on Transaction record and main line is false, because more than 1 line for same record will come and you can not add internalid noneof array as it may skip few results which false after 1000 limit.

    You can also read below article.There are always best way not you have to choose which one you like.
    http://netsuiteguru.blogspot.in/2016/12/how-to-get-more-than-1000-records-in.html

    ReplyDelete

Post a Comment

Thanks for you message, please join us on Facebook and Linkedin