Thursday, June 6, 2019

Dynamic Search using RESTlet

Dynamic Search using RESTlet

To create a dynamic search for records based on the parameter passed by the user, the snippet of code below can be used as a guide. For this particular sample, we will be using the location specified by the user as the criteria in searching for item records.

function getRestlet(data)

     //array which contains the user-defined passed parameter
     var a = new Array();
     a.push(data.location);

     //array for the filter
     var filters = new Array();
 
     //uses location as the search criteria based on the location parameter passed by the user
     filters[filters.length] = new nlobjSearchFilter('location', null, 'anyof', a);
 
     //array for the columns
     var columns = new Array();

     //shows the name of the item on the search results
     columns[columns.length] = new nlobjSearchColumn('itemid');
  
     //searched the item records
     var searchResults = nlapiSearchRecord('item', null, filters, columns);
 
     //returns the array of the search results
     return searchResults;
}

No comments:

Post a Comment