Wednesday, October 24, 2018

Use Restlet to return a saved search

To return a saved search using a Restlet, use the following code as guide:

function GetSearchResult(){
    //array container for search results
    var output = new Array();
   
    //get search results
    var results = nlapiSearchRecord('customer','customsearch13',null,null);
    var columns = results[0].getAllColumns();
   
    //loop through the search results
    for(var i in results){
        //create placeholder object place holder
        var obj = new searchRow(
          //set the values of the object with the values of the appropriate columns
          results[i].getValue(columns[0]),
          results[i].getValue(columns[1]),
          results[i].getValue(columns[2]),
          results[i].getValue(columns[3]),
          results[i].getValue(columns[4]),
          results[i].getValue(columns[5]),
          results[i].getValue(columns[6]),
          results[i].getValue(columns[7])
          );
       
        //add the object to the array of results
        output.push(obj);
    }
   
    //return the array of search objects
    return output;
}

//Object to serve a place holder for each search row
function searchRow(id,name,email,phone,ofcphone,fax,contact,limit){
    this.id = id;
    this.name = name;
    this.email = email;
    this.phone = phone;
    this.ofcphone = ofcphone;
    this.fax = fax;
    this.contact = contact;
    this.creditlimit = limit;

}

Note:
-An object placeholder needs to be created to make sure the results returned by the Restlet is similar to what is returned by the saved search in the UI.


No comments:

Post a Comment