2

I am trying to retrieve records in Netsuite via SuiteScript. I would like to use the lastmodifieddate column to fetch record after a certain timestamp.

I am currently doing:

var filters = [new nlobjSearchFilter('lastmodifieddate', null, 'notbefore', time)];
var columns = [new nlobjSearchColumn('lastmodifieddate')];
var newSearch = nlapiCreateSearch(table, filters, columns);
var searchResultSet = newSearch.runSearch();
var back = nextEndIndex - 1000
var results = searchResultSet.getResults(back, nextEndIndex);

Where time is a datetime JS, nextEndIndex index counter for results.

This works for some objects but majority of Netsuite objects do not have the lastmodifieddate column in the record browser. Is there a built in variable for the lastmodifieddate? And if there is, how can I use it in nlapiCreateSearch? If you have better ways to do it, I would be grateful for the info.

quarks
  • 33,478
  • 73
  • 290
  • 513
reggieble
  • 21
  • 1
  • 6

3 Answers3

3

Here is a simple example for SuiteScript 2.0.

define(['N/search'],function(search){
  function test(chkDate){
    log.debug(chkDate);
    var empSearch=search.create({
      type:search.Type.EMPLOYEE,
      columns:['internalid','firstname','lastmodifieddate'],
      filters:['lastmodifieddate','after',chkDate]
    }).run().each(function(result){
      log.debug(JSON.stringify(result));
      return true;
    });
  }
  test('05/30/2017');
});

This example is searching for employees, since I was not sure which record type you were looking at. Below are links to the information you can use to build out your searches:

  1. Records Browser (look at the bottom of each section in the filters and columns):
  2. Search Operators (shows which ones to use for which field types)
  3. API Docs
w3bguy
  • 2,215
  • 1
  • 19
  • 34
  • That is another good way to do it. But majority of the records do not have the `lastmodifieddate` column in the Records Browser. There is a `date_last_modified` column but it is only available in the Connect Browser (reserved for ODBC connections). Is there a way to search objects without the `lastmodifieddate` for their last modification timestamp? – reggieble Jun 02 '17 at 07:12
  • I see lastmodifieddate on every standard record, and I use it regularly. – w3bguy Jun 02 '17 at 12:34
1

Transactions are slightly different than entities. Transactions have lines. If you are trying to determine the true last modified date of a transaction, you may need to consider using the "Line Last Modified" field in place of "Last Modified Date." Try writing a simple search to pull Sales orders. Include "Last Modified Date" and "Line Last Modified." Then write a simple formula to show those that don't match. When I did this, there were a number of mismatches, with instances of "Line Last Modified" being more than 1 month later than "Last Modified Date." So if you are looking for the true last modified date, you may need to use the max "Line Last Modified."

Kevin M
  • 189
  • 2
  • 10
0

You could use a 'Max' Summary Filter on {systemnotes.date} - you will of course need to Group by record (document number or internal id for example) for this to show correct results.

Krypton
  • 4,394
  • 2
  • 9
  • 13