This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Feb 23, 2011, 7:48 PM
66 Posts

Display alert/message to user when using SSJS

  • Category: Server Side JavaScript
  • Platform: All
  • Release: 8.5.2
  • Role: Developer
  • Tags: SSJS,server side javascript
  • Replies: 4
What have you guys found to be the simplest way to alert users when using SSJS? For example, in a simple If, Else statement:
 
if (subStatus === "Yes") {
   return false;
   alert("Document cannot be removed");
}
else {
   doc.remove(true);
   alert("Document removed");
}
 
Being that "alert()"  is not available in SSJS, is there a different way to do this with XPages?
Feb 23, 2011, 7:54 PM
40 Posts
Re: Display alert/message to user when using SSJS
In what context to you want to alert the user that you want to integrate it into SSJS.  What I do is if I meet a condition that requires the user to know something, I code it into the UI through something that looks like the validation error message 
Feb 23, 2011, 8:53 PM
66 Posts
Re: Display alert/message to user when using SSJS
I ended up realizing that I could just use a client side "(confirm())" script and then do my SSJS logic after that.
 
This article helped: http://www.jmackey.net/groupwareinc/johnblog/johnblog.nsf/d6plinks/GROC-7GLFZG

Thanks for the response Jeremy.
Feb 23, 2011, 11:51 PM
22 Posts
Re: Display alert/message to user when using SSJS
I believe you may be able to use the onComplete event of the SSJS to notify a user as well.
 
Typically, you would set the value of a hidden input field to the value of the alert content with the SSJS, and then simply grab that value (typically innerHTML) with the CSJS and use it in your alert statement.
 
You'll find the onComplete event in All Properties when you have the SSJS selected in the Source pane (well, that's how I find it anyway!). 
Feb 24, 2011, 9:11 AM
261 Posts
Re: Display alert/message to user when using SSJS
  • Add en "Display Errors" control to every XPage.
  • In your SSJS, add a FacesMessage to the facesContext for every error, e.g.:
var id = "myErrorMessages";
facesContext.addMessage(id,  new javax.faces.application.FacesMessage("Show this message to the user"));
 
If you do not want to use the default "Display Errors" control, you can also use (for instance) a Computed Field that reads the messages from the facesContext, e.g.:

var msgIt = facesContext.getMessages("myErrorMessages");

var msg = [];
while (msgIt.hasNext() ) {
        msg.push(msgIt.next().getSummary());
}
return msg.join("<br>");


This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal