The data from a record cannot be accessed when the record is in the view mode, using the client script. Then use the search to access the values from the record. Pass the id of the record to the filter of the search.
function sendCustomerDetails() {
try {
var customerRec = currentRecord.get();
var recordId = customerRec.id;
var customerSearchObj = search.create({
type: "customer",
filters:
[
["internalid", "anyof", recordId]
],
columns:
[
search.createColumn({name: "companyname", label: "Company Name"}),
search.createColumn({name: "category", label: "Category"}),
search.createColumn({name: "email", label: "Email"})
]
});
var searchResultCount = customerSearchObj.runPaged().count;
var resObj = {};
customerSearchObj.run().each(function (result) {
resObj.companyName = result.getValue({name: "companyname", label: "Company Name"})
resObj.category = result.getValue({name: "category", label: "Category"})
resObj.email = result.getValue({name: "email", label: "Email"})
});
return resObj;