/**
* Function to get the primary contact
* @param {*} salesOrderId sales order id
* @param {*} recType record type
* @returns transaction details
*/
function getPrimaryContact(salesOrderId, recType) {
try {
let primaryContactName;
let estimateSearchObj = search.create({
type: "transaction",
filters:
[
["type", "anyof", recType],
"AND",
["mainline", "is", "T"],
"AND",
["internalid", "anyof", salesOrderId]
],
columns:
[
search.createColumn({ name: "internalid", label: "Internal ID" }),
search.createColumn({
name: "entityid",
join: "contactPrimary",
label: "Name"
})
]
});
var searchResultCount = estimateSearchObj.runPaged().count;
log.debug("estimateSearchObj result count", searchResultCount);
estimateSearchObj.run().each(function (result) {
// .run().each has a limit of 4,000 results
primaryContactName = result.getValue({
name: "entityid",
join: "contactPrimary",
label: "Name"
});
});
log.debug('primaryContactName', primaryContactName);
return primaryContactName;
} catch (e) {
log.error('error @ getPrimaryContact', e);
return '';
}
}