Get Sales Rep — Restlet

To get sales rep details from the NetSuite. Sales rep email will be sent from the front end (Magento) and if there is a sales rep with the corresponding email then the sales Rep details will be sent back. If the sales rep could not be found then the false flag will be returned.

function getSalesRep(datain)
{
/*  var err = new Object();
  
  if (!datain.recordtype)
  {
    //err.status = "failed";
    //err.message = "missing recordtype";
    return "Failed";
  }
*/  
  var ret = new Object();
  
  try {
    var columns = new Array();
    columns[0] = new nlobjSearchColumn('entityid', null, null);
    columns[1] = new nlobjSearchColumn('salesrep', null, null);
    columns[2] =  new nlobjSearchColumn("email","salesRep",null);
    var input = JSON.parse(datain);
    nlapiLogExecution('DEBUG', 'InputID', input.id);
    var searchRes = nlapiSearchRecord("customer", null, ["formulatext: {entityid}","is", input.id], columns);
    
    if (searchRes.length == 0)
      return "Nothing";
    else
      nlapiLogExecution('DEBUG', 'MatchCount', searchRes.length);
/*    
    for(var i = 0; searchRes != null && i < searchRes.length; i++){
      var item = searchRes[i];
      nlapiLogExecution('DEBUG', 'Entity', item.getValue('entityid'));
    }
*/
    var cust_record = searchRes[0];
	
    //var cust_record = nlapiLoadRecord("customer", datain.id);
    var salesrepId = cust_record.getValue('salesrep');
    var salesrepemail = cust_record.getValue('email','salesrep',null);
    nlapiLogExecution('DEBUG', 'SalesRep Name', cust_record.getText('salesrep'));

    nlapiLogExecution('DEBUG', 'cust_record.getValue Name',  cust_record.getValue('email','salesrep',null));
    
 //   var salesrep_record = nlapiLoadRecord("employee", salesrepId);
/*    
    ret.firstName = salesrep_record.getFieldValue('firstName');
    ret.lastName = salesrep_record.getFieldValue('lastName');
*/    
    ret.name = cust_record.getText('salesrep');
    ret.email = salesrepemail ;

  }
  catch (e) {
    nlapiLogExecution('DEBUG', 'Err', e.toString());
  }
      
/*  
  var employeeSearch = nlapiSearchRecord("employee",null,
  [
     ["title","is","Sales Rep"]
  ], 
  [
     new nlobjSearchColumn("entityid",null,null).setSort(false), 
     new nlobjSearchColumn("email",null,null), 
     new nlobjSearchColumn("phone",null,null), 
     new nlobjSearchColumn("altphone",null,null), 
     new nlobjSearchColumn("fax",null,null), 
     new nlobjSearchColumn("supervisor",null,null), 
     new nlobjSearchColumn("title",null,null), 
     new nlobjSearchColumn("altemail",null,null), 
     new nlobjSearchColumn("custentity1",null,null)
  ]
  );
*/  
  nlapiLogExecution('debug', 'title', JSON.stringify(ret));
  return JSON.stringify(ret);
}

Leave a comment

Your email address will not be published. Required fields are marked *