Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
saar_dagan
Employee
Employee

The portal broadcast messaging feature is provided with an out-of-the-box sample UI.

Most customers would want to customize the UI to fit their framework page.


You can find more on the BCM here:

New Development: Broadcast Messages in SAP NetWeaver Portal


If you wish to use the BCM out of the box sample UI you will need to add it to your classic/afp framework page,

The application can be found under Portal Content >> com.sap.portal.broadcast.message.framework >> Sample_BroadcastMessageIview

In order to allow this we have opened a client-side API that allows developers to create their own iView and interact with the BCM service.


Prerequisites:

  1. You have installed SAP NetWeaver Portal (EP) 7.31 SP11 or above.
    • You have created a delta link for the Broadcast Message Framework iView in your framework page and set it to visible. This iView is located under Portal Content >> Portal Users >> Standard Portal Users >> iViews >> Broadcast Messages
  2. You have enabled the BCM service by setting the BCM is active property to true.

               

The API

The client side API is under the object window.BCM.API and contains the following methods:

isPollingActive() - this method checks if the BCM polling mechanism is active. If the mechanism is not active, the broadcast messages will be taken from the server only once.

getPollingIntervalTime() - This method returns the number of minutes between each request to the server.

getActiveMessagesForCurrentUser(success callback function, fail callback function) - This method gets all of the user’s broadcast messages (according to the user’s roles and groups) and return them to the success callback function in a JSON format (if successful) or returns a JSON with the status "fail".

Each message in the JSON has the following attributes:

    • messageId - The message ID, which is a unique ID for the message in the server.
    • messageBody - The actual message body.
    • isRead - A boolean stating if this message has already been read by this specific user.
    • isPriority (added in SP12) - A boolean that indicates whether this message has a higher priority.

setMessageAsRead(message ID, callback function for status) - Sets the message state to "already read" for this user in the UCD.

The callback function will receive a JSON with a "success" or "fail" status.

Example:

window.BCM.API.getActiveMessagesForCurrentUser(onMessagesReceived, onNotMessagesReceived);


   function onMessagesReceived(messagesJSON){
    //check that the actual size of the messagesJSON is more than 0.
    if(messagesJSON.length > 0)
    {
     var newMessagesArrived = false;
     for(var i = 0; i < messagesJSON.length; i++)
     {
      createMessage(messagesJSON[i].messageId, messagesJSON[i].messageBody, messagesJSON[i].isRead, messagesJSON[i].isPriority);
      // check that this message was not already read and update the new messages flag.
      if(!messagesJSON[i].isRead)
      {
       newMessagesArrived = true;
      }
     }
    }
   }



------------------------------------------------------------------------------------------------------


       window.BCM.API.setMessageAsRead(messageId,function(data){
        // check if the operation has failed or succeeded.
        if(data.status !== "success"){
         if(window.console){
          window.console.log("couldn't set message: "+data.messageId+" as read");
         }
        }
        else{
         // if operation succeeded mark message as read in the user interface
         changeMessageBackground(messageId);
        }
       });


If you would like to learn more regarding the BCM API please ask for information in the comments and I will try to add it to the article.

Saar

36 Comments