简体   繁体   中英

How to search for employee name using internal id? Suitescript 2.0

How do I search for an employee's name using their internal Id? I've tried using the getText function on the object to get the sales rep name instead of the internal id, but SS2.0 won't allow that. I've also tried using a search.fieldLookUp function, but that spat out errors for me too.

/**
 * @NApiVersion 2.0
 * @NScriptType UserEventScript
 */

define(['N/search'],

function(search) {

    return {
        afterSubmit : function(context){
            //log.debug('hello world');
            var customer = context.newRecord;

            var custId = customer.getValue('entityid');
            var custEmail = customer.getValue('email');
            var salesRep = customer.getValue('salesrep');

You can use search lookup to retrieve the employee's name:

var employeeNameFieldLookUp = search.lookupFields({
    type: search.Type.EMPLOYEE,
    id: employeeInternalId ,
    columns: ["firstname", "middlename", "lastname"]
});

var firstname = employeeNameFieldLookUp.firstname;
var middlename = employeeNameFieldLookUp.middlename;
var lastname = employeeNameFieldLookUp.lastname;

var employeeName = [firstname, middlename, lastname].join(" ");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM