/**
* Finds the internal ID of an employee based on the partner name.
*
* @param {string} partnerName – The name of the partner to search for.
* @returns {string|null} The internal ID of the employee or null if not found.
*/
const findEmployeeIdByName = (partnerName) => {
try {
const employeeSearch = search.create({
type: search.Type.EMPLOYEE,
filters: [
[‘entityid’, ‘is’, partnerName],
‘AND’,
[‘salesrep’, ‘is’, ‘T’]
],
columns: [‘internalid’]
});
const searchResult = employeeSearch.run().getRange({ start: 0, end: 1 });
log.debug(“searchResult”,searchResult)
log.debug(“searchResult[0].getValue(‘internalid’)”, searchResult[0].getValue(‘internalid’));
return searchResult.length > 0 ? searchResult[0].getValue(‘internalid’) : null;
} catch (e) {
log.debug(“Error in findEmployeeIdByName”, e);
return null; // Return null in case of error
}
};