title: NetSuite SuiteScript 2.0 How to specify field, sublist field or subrecord field in N/search create API
body: <p>I have a button on the Purchase Order record that performs a saved search query on the current record and then uses the http module to send that data via a POST to a url. That url then sends the data posted back as part of the success confirmation. The idea with the saved search is to create a javascript object that contains all the data that I want from the purchase order (main record and items sublist with subrecords) and then to use <code>JSON.stringify</code> to create a JSON payload for the http POST. I can't do this with the <code>currentRecord</code> because if you inspect it it only contains the internal id. This would also prevent me from having to go to the great lengths of writing a lot of code to manually build up a JSON string from the <code>currentRecord</code>.</p>
  
  <p>Unfortunately I don't really understand how to specify the column names in the dynamically created saved search. Sometimes it looks to me like the column names are those from the NetSuite Records Browser and other times the script gives an error (column not found) if I use a column name from the NetSuite Records Browser (for example <code>currencysymbol</code>). </p>
  
  <p>I'm also not sure how to specify columns that appear in sublists or subrecords in sublists. I tried to use <code>item.itemtype</code> but this gave me a column not found error. Just <code>item</code> completes successfully but I'm not sure whether this was really successfull since it is difficult to decode the returned result after the <code>JSON.stringify</code> (it adds a lot of backslashes). Using <code>console.log</code> (for some reason I don't get anything back using the NetSuite <code>log.audit</code>) is also quite difficult, although it looks like it is returning an array with 5 rows. So using <code>item</code> might sort of be successful. I say sort of because I have 3 item lines and it is returning 5 array rows.</p>
  
  <p>So basically I would like to know where one can find the names of the columns to use in NetSuite for a saved search; and also how to specify sublist column names and sublist subrecord column names in a saved search.</p>
  
  <pre><code>/**
   * @NApiVersion 2.0
   * @NScriptType ClientScript
   * @NModuleScope SameAccount
   */
  define(['N/ui/dialog', 'N/currentRecord', 'N/record', 'N/url', 'N/http', 'N/search'], function (dialog, rec, record, url, http, s) {
  
     function pageInit(context) {
        // All client scripts need at least one dummy function.
     }   // pageInit
  
     function onButtonClick() {
  
        var currentRecord = rec.get();
  
        // Create a saved search dynamically.
        var rs = s.create({
           type: s.Type.PURCHASE_ORDER,
           filters: [
              ["mainline", s.Operator.IS, "F"], "and",
              ["internalid", s.Operator.IS, currentRecord.id]
           ],
           columns: [
              "internalid",
              "currency",
              {
                  name: "item",
                  sort: s.Sort.ASC   // DESC
              }
           ]
        });
  
        var myPostDataObj = rs.run().getRange(0, 1000);
        console.log(myPostDataObj);
        var headers = {
           'Content-Type': 'application/json; charset=utf-8',
        };
        http.post.promise({
           url: 'http://httpbin.org:80/post',
           body: JSON.stringify(myPostDataObj),
           headers: headers
        })
        .then(function(response){
           console.log('SUCCESS: ' + JSON.stringify(response));
        })
        .catch(function onRejected(reason) {
           console.log('ERROR: ' + JSON.stringify(reason));
        })
  
     }
  
     return {
        pageInit: pageInit,
        onButtonClick: onButtonClick
     };
  
  });   // Define
  </code></pre>