function empLocationSearch(currentEmpID) {
try {
var employeeSearchObj = search.create({
type: "employee",
filters:
[
["internalid", "anyof", currentEmpID],
"AND",
// ["location","anyof","29"]
["isinactive", "is", "F"],
],
columns:
[
search.createColumn({ name: "internalid", label: "Internal ID" }),
search.createColumn({ name: "location", label: "Location" })
]
});
var searchResultCount = employeeSearchObj.runPaged().count;
log.debug("searchResultCount", searchResultCount)
let location
if (searchResultCount > 0) {
employeeSearchObj.run().each(function (result) {
location = result.getValue({
name: "location", label: "Location"
})
});
return location;
}
else {
return false
}
}
catch (err) {
log.debug("error@empLocationSearch", err)
}
}
let sales_location_field = currentform.addField({
id: 'custpage_saleslocation_field',
type: serverWidget.FieldType.TEXT,
label: 'Sales Associate Location'
})
let salesAssociateLocation = empLocationSearch(salesAssociate)
if (salesAssociateLocation) {
currentRecord.setValue({
fieldId: 'custpage_saleslocation_field',
value: salesAssociateLocation
})
}
sales_location_field.updateDisplayType({
displayType: serverWidget.FieldDisplayType.HIDDEN
});