Short version: Can I return my own messages in the javascript remote event.message object?
Long version: I use a javascript remote call to perform an ajax search.
This is the code (pretty much just use the standard SF provided example):
function ajaxSearch() {
var searchBoxValue = document.getElementById('searchValue_sharing_search').value;
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.TestExtension.ajaxGetRoles}',
searchBoxValue,
function(result, event){
if (event.status) {
buildRoleMap(results);
} else if (event.type === 'exception') {
document.getElementById("responseErrors").innerHTML =
event.message + "<br/>\n<pre>" + event.where + "</pre>";
} else {
document.getElementById("responseErrors").innerHTML = event.message;
}
}
);
}
This works great. However, sometimes a search comes back empty. I want to have a message appear on my Visualforce page telling the user why nothing comes back. I could just use Javascript to inspect the result. Something like this:
function(result, event){
if (event.status) {
if (result === '[]') {
//create and display message
}
However, Javascript remoting already returns an event object which has messages, and I already have a way to display them on the page. Like so (taken directly from the SF example):
else {
document.getElementById("responseErrors").innerHTML = event.message;
}
Maybe this is a rookie question, but can I return my own messages in the event object? All I can find on the subject from SF docs are that 'The event object is typically used only in debugging and sophisticated error management'.
Is it possible? Or is there a better way I am unaware of?