Tip 22: Get Record ID from a Saved Search GroupBy Results in Map/Reduce Script in NetSuite Suitescript 2.0

Hello Friends,

Sorry for delay in posting next tip.

Here is one for you hoping this will help you.

This tip will be helpful if you are working in SuiteScript 2.0.

Believing you have prior knowledge of SuiteScript 2.0 & Map/Reduce script:

In Map/Reduce script, usually we send Search Resultset to Map(context).

And inside Map(), we get Record ID by using code:

var recordId = searchResult.id;

But what if, your search runs by summary??

Below is a sample script code that will help you to run Map/Reduce script based on Summary search.

Requirement: I want to generate JE against each In progress Project including Amounts grouped by Invoices of each Project.

Step 1: Create Saved Search:

My 1st step will be to create a saved search on project record

Record Type: Project

Status: In progress


  1. Field: Internal ID, Summary: GROUP
  2. Field: Name, Summary: GROUP
  3. Field: Transaction: Amount, Summary: SUM

Internal ID of the saved search: ‘customsearch_project_list’

Step 2: Create Map/Reduce Script:

Create Map/Reduce script with file name MRS_Create_JE_Against_Projects.js

Sample Code for MRS_Create_JE_Against_Projects.js:

* @NApiVersion 2.0
* @NScriptType MapReduceScript
define([‘N/record’, ‘N/search’, ‘N/runtime’, ‘N/email’],

* This script will search all Project with Sum of Amounts of Invoice related to project and creates JE against each project
function(record, search, runtime, email){

var SAVED_SEARCH_ID = ‘customsearch_project_list’;
var ACC_CREDIT = “<Credit Account ID>”;
var ACC_DEBIT = “<Debit Account ID>”;

* The following function is required for map/reduce scripts. It is called once as the entry point of the script.
* This function will search search all Project with Sum of Amounts of Invoice related to project and creates JE against each project
* @param {Object} context : context object
* @governance 0 units
function getInputData(){
var searchObj = search.load({
id : “customsearch_project_list”
var arrResults = new Array();
var id = “”, amount = 0.00;

//Run each result and get ID and push it to array
searchObj.run().each(function(result) {
id = “”;
id = result.getValue({name: “internalid”, summary: “GROUP”});

amount = result.getValue({name: “amount”, join: “transaction” summary: “SUM”});
arrResults.push({“id”: id, “amount”: amount});
//Return array of IDs-Amount which will be passed to Map() function instead of Search Object
return arrResults;
log.error(‘getInputData error: ‘, ex.message);

* The following function is required for map/reduce scripts. It is called for each key/value pair in the getInputData function.
* For each Project record found in search result, get ID & Amount and create JE against each project record
* @param {Object} context : context object
function map(context){
var searchResult = JSON.parse(context.value);
//Get Project ID and its Amount
  var projectId = searchResult.id;

              var amount = searchResult.amount;
log.debug(“MAP Project IS – Amount”,  projectId + ” – ” + amount);
//Add code to create JE against this Project ID
log.error(“Error in Map”, JSON.stringify(ex));
getInputData: getInputData,
map: map

Now your script is ready. Upload this file and create Map/Reduce script. Now deploy and execute this script and see the result.

As you see here, we are not returning search object in getInputDate() unlike general Map/Reduce script.

Instead we are sending array of objects which hold IDs and Sum of Invoice Amounts to map() function for next execution.


Hope that helps you.

Also, let me know, if you want any tips on Map/Reduce on specific requirement.

I will add it, is I have any expertise on that.


Happy Coding 🙂



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.

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 🙂



Tip 14 – Show sub customer’s Transactions on Parent Customer’s record as sublist

Hi Friends,

Coming back again with a new simple tip, that will help you, as this is very common requirement, that every Netsuite account owner needs.

Requirement was like: As a Netsuite user, I should see all Sales Order created by all the sub customers on parent customer as a sublist.

As per Netsuite’s standard functionality, customer record shows all the transacts created by that customer only.


Fortunately the requirement is achieved by Saved Search. How??? Check below steps…

Step 1: Create a Saved Search on Customer record

A)Set Criteria:

1.Type: is Sales Order

2.Main Line: is True


B)Set Results:

Add fields as shown below figure:


C)Set Available Filters:

Add Field Parent:Internal ID in Available Filter section as shown below.


Now Save the Saved Search.

Step 2:

1.Go To Customization -> Forms -> Sublists as below.


Now click Entity Tab and select the saved search that you have created just now. Add the tab on which you want to show and select Customer checkbox as shown below.


Now add and save.

Now Go to the Customer record -> Sales -> Cost Center Transactions and see the results.



I hope this will help you guys and this is specially for someone who is very new to Netsuite.






Tip:13 – Add Link to text in results of Netsuite Saved Search

Most of us must have faced the issue of Record Number/Name not displaying as a link but as a text in saved search results.

When in a saved search result, we need to show Parent -> Child -> Sub Child’s field, its difficult to create saved search on Parent record.

So we approach with saved search on Child Record, so that we can fetch column on Parent as well as its child’s column like:

Parent’s Fields<- Child -> Child’s Fields

But we need to make sure, that the saved search results should appear like the saved search is on Parent’s record.

In that condition sometimes, we won’t get link on Parent’s fields like its Number, its Customer/Vendor, so that on click of the link, we should redirect to Parent’s record instead of Child’s record.

Saved Search

I would link to share my findings on the same issue.


Instead of adding Number/Customer Name/Vendor Name, add Formula(Text) in results column.

Ex:  For Number:

Column: Formula(Text)

Formula: ‘<a href = https://system.na1.netsuite.com/app/common/custom/custrecordentry.nl?rectype=484&id= ‘||{custrecord1401.internalid}||’>’||{custrecord1401.name}||'</a>’

Here remember below points:

  1. Use “<a>” HTML tag for adding link to the specific field in results.
  2. The “href”  value should be the address URL same as to open a new record of that type like: “<a href = https://system.na1.netsuite.com/app/common/custom/custrecordentry.nl?rectype=484&id=
  3. Netsuite uses “||” while adding fields to HTML tags. Use carefully while adding this symbol. Use “||” before and after the field name like ||{custrecord1401.name}||.
  4. ||{custrecord1401.name}|| should always be within single quote() like ‘||{custrecord1401.name}||’.
  5. Use the field within “<a>” & “</a>” like ” ‘<a>’||{custrecord1401.name}||'</a>’ “.
  6. Now add the internal ID field for “id=” parameter in the URL like: ‘<a href = https://system.na1.netsuite.com/app/common/custom/custrecordentry.nl?rectype=484&id= ‘||{custrecord1401.internalid}||’>’||{custrecord1401.name}||'</a>’.
  7. DON’T  use “+” sign while adding id field to the parameter that we generally do for other languages.
  8. Now click Add and “Save & Run”. Now you must be able to see the link on the Number/Name. On click of that, you must be redirected to that record.

Hope this tip will help you.

Comments/Suggestions are appreciated.



Tip 11 – Show list of Partially/Pending fulfillement Sales Orders excluding dropship items

Hello friends,

This blog is related to a saved search which includes only sales order which are partially fulfilled or pending fulfillment.

Note: Let’s say if Client is using drop-shipment feature, that means, item will be delivered directly to customer from Vendor, which is nothing to do with client’s inventory.


Item drop-shipment feature can be used in two possible ways.

-We can directly check the Item Dropship checkbox in Item record itself, so that as soon as we add the item to the Sales Order, a Purchase Order will be created and that will be handled as Drop-shipment.

-Another way is to select an item which you want to opt for drop-shipment in that particular Sales Order, and select the “Drop Ship” option in Create PO column. A Purchase Order record will be created which will be used for drop-shipment.

Now let’s start creating the saved search.

Step 1: Create a saved search for Transaction record type

Step 2:

In Criteria:

-Filter 1: Type: Sales Order

-Filter 2: Status: any of – Sales Order:Partially Fulfilled, Sales Order:Pending Fulfillment

Now, to filter the dropship item in the saved search, you need to keep the below point in mind.

-When Item is checked for dropship in Item record, use below filter in criteria:

Case 1 – Filter 3: Item:Dropship Item is Yes

-When Item is selected for dropship in Sales Order record(select Dropship in Create PO column of Sales Order), use the following filter

Case 2 – Filter 3: Purchase Order:Applied To Link Type – is not – Drop Shipment

Remember, if you are using both in Item level as well as in Sales Order lever, use both the filters in “OR” condition using Advance Filter option.

Filter 4: Main Line is false

Filter 5: Shipping Line is false

Filter 6: Tax Line is false

Filter 7: COG Lina is false


In Results:

Add the fields as per your result’s requirement.

Now save and run the saved search and see if you get the desired results.

Point to be noted:

-You can’t get the Create PO column in the filter criteria in the saved search.

-You can’t use Applying Link field in the filter criteria, as it will show all the transaction link that has been processed for the same item in the Sales Order. So, you may get the dropship item, even though you have filtered using the criteria, as it belongs to some other linked value along with dropship as below image.


Hope next time when you get similar requirement, you won’t struggle like me.

Enjoy Coding 🙂



Tip 6: Inline Editing in Saved Search results in Netsuite

Inline editing the List of any record type is a feature, where user can edit the value of a field(shown in the list) in any record listed in the List

without doing

-> going to the specific record -> editing the record -> editing the field -> saving the record

which obviously a brilliant feature that Netsuite has.

I am happy that Netsuite provides the same feature for Saved Search results which any organization who is using Netsuite may need.

I had the same requirement, where client was asking for creating a saved search where user can see the desired results and and manipulate the price fields as per their need.

Many of us may know about this, but still I am posting to let others know if they don’t still… 🙂

While achieving this, we have to take care of certain things:

  • You must have access to edit the record
  • You must have access to edit that field
  • Inline Editing must be enabled in this record form
  • The field should be shown in the particular record form
  • Display type of the field should be normal in the form
  • Saved Search should be enabled for editing

After all the above mentioned lines are taken care, check if Edit button is green or not in Saved Search results.

Oh….Prior to above points…you must have created a saved search on which you want to achieve the inline editing feature.

If the Edit button is checked with green edit then, you can see the field labels must have a pencil image on the right side pencil. It means, you can add/Edit the field now.

Click on the column with the specific record line, on which you want to add/edit the text. Write your desired text and hit outside. Your record is saved with new field value….that’s it…Its cool….

See the figure below with the saved search and how its edited.Editable Saved Search

Hope this will help you…