Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The following document describes how error, warning and question messages are developed in our system. Generally, a certain procedure is been followed, starting from constructing a method which will call a calls the message statement or throw an exception message whilst metadata and translation files should be changed accordingly to show the appropriate messages on the screen. Although, we are going to discuss three different illustrative examples below.

...

Error messages are appeared many times in the system, but we are going to discuss an example with accounts receivable, where we validate the credit period for an account. Firstly, a method is constructed in the account receivable business object (BO) which tries to validate the credit period of an account and throws an exception for invalid account credit periods. This exception must be is also implemented and note that it extends the Exception class as follows:

...

Furthermore, the exception message should be defined in message metadata file with caps and the correct datapath as code whilst an expression and a description for the exception is needed.

 

Code Block
themeEclipse
titlemessages.xml
collapsetrue
<messages>
...
	<message>
       <code>COM.CRM.EXCEPTION.ACCOUNTS.INVALIDACCOUNTCREDITPERIODEXCEPTION</code>
       <expression>key_com_crm_exception_accounts_invalidaccountcreditperiodexception</expression>
       <description>Invalid Credit period %1 based on definition (%2 % 3).</description>
    </message>
...
</messages>

...

In general, It is important to mention that question messages are implemented exclusively for interfaces. Thus, let see an example of creating a question message for post payments. Firstly, a method named postPaymentButton is constructed to call another method which will show the question message as follows. The nested method parses the class name of the function to be called if the Yes option is chosen, then . Then it passes the function, the code of the question message as it is defined in the messages metadata file and lastly the parameters of the message.

...

Below, we can see the scenario with the payment post. The question message is appeared appears on the top of the screen and ask you if you want to continue and posting post the payment.

 

Expand
titleQuestion Message

...

Below, the InfoMessage method is implemented, extends the Exception and it also has the parameters, which are mentioned before:.

 

Code Block
themeEclipse
languagejava
titleCRMUILicenseBean.java
collapsetrue
package com.crm.process;
import com.crm.businessobject.CRMSession;
import com.crm.framework.metadata.Message;
import com.crm.framework.metadata.MetadataUtil;
import com.crm.framework.util.StringUtil;

public class InfoMessage {
    
    private String message;
    
    public InfoMessage(CRMSession crmSession, String code, String[] msgParams, String context, String mpID) throws Exception {
        
        super();
        
        Message infoMsg = MetadataUtil.getMessage(context, mpID, code);
        
        if (infoMsg!=null)
        {
            this.message = crmSession.getTranslation(infoMsg.getExpression());
        }
        
        if (msgParams!=null && msgParams.length>0)
        {
            for (int i=0;i<msgParams.length;i++)
            {
                String msgParameter = "%" + (i+1);
                if(msgParams[i].startsWith("key_"))
                    this.message = StringUtil.replace(this.message, msgParameter, crmSession.getTranslation(msgParams[i]));
                else
                    this.message = StringUtil.replace(this.message, msgParameter, msgParams[i]);
            }
        }
    }
    public String getMessage() {
        return message;
    }
    
}

...