Versions Compared

Key

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

This section describes how error, warning, and question messages are created.

 

What does this section cover?

Table of Contents

 

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 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

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 credit periods. This exception is also implemented and note that it extends the Exception class as follows:

 

...

themeEclipse
languagejava
titleInvalidAccountCreditPeriodException.java
collapsetrue

...

Error Messages

Expand
titleError Message

Image Added

In order for an error message to appear on screen, a java exception must be created and thrown. 

  1. Create the Exception class. 
    1. All exception classes must extend com.crm.exception.CRMValidationException
    2. All exception methods should have a com.crm.exception.CRMValidationException object as an input parameter and use setMessage method of com.crm.exception.CRMException class.
      1. To create the exception method:
        1. Use com.crm.businessobject.CRMSession object as an input parameter and any other String input parameters needed.
        2. Put all String input parameters in a String ArrayList.
        3. Use setMessage method of com.crm.exception.CRMException class to construct the exception message.
Code Block
languagejava
titleAccountTerminationException.java
collapsetrue
 public class AccountTerminationException extends CRMValidationException {
	/**
	 * You are not allowed to terminate the Accounts Receivable %1. This is only allowed for Active or Suspended accounts.
	 * 
	 * @param crmSession - the session object
     * 
    	 * @param value1 - the first exception value
     * @param value2 - the second exception value
	     * @param value3 - the third exception value
     * 
     * @throws Exception
	     */
    	public InvalidAccountCreditPeriodExceptionAccountTerminationException(CRMSession crmSession, String value1, String value2, String value3value) throws Exception {

       
        		super();

       
        		ArrayList<String> parameters = new ArrayList<String>();
        
        		parameters.add(value1value);

       parameters.add(value2);
        parameters.add(value3);
        try 
        {
            		try 
		{
			setMessage(this.getClass().getName().toUpperCase(), crmSession, parameters);
        		} 
        		catch (Exception e) 
        {
            		{
			e.printStackTrace();
        		}
    	}
}

...

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

 

...

in the messages.xml file. Use a unique key for the expression tag.  For more information on customising messages metadata, go to Customize Messages Metadata.

Code Block
languagexml
titlemessages.xml
collapsetrue
<messages>
...
	<message>
       		<code>COM.CRM.EXCEPTION.ACCOUNTS.INVALIDACCOUNTCREDITPERIODEXCEPTION<ACCOUNTTERMINATIONEXCEPTION</code>
       		<expression>key_com_crm_exception_accounts_invalidaccountcreditperiodexception<accountterminationexception</expression>
		<description>You are not allowed to terminate the accounts <description>Invalidreceivable. CreditThis periodis %1only basedallowed onfor definitionActive (%2or %Suspended 3)accounts.</description>
    	</message>
	.
	.
	.
</messages>

 

Then, the key expression mentioned above has to create an entry key in the label page and define the exact error message that will be appeared on the screen as follows:

 

...

      3. Define the exception in English translation properties file, by using the expression tag key defined in metadata messages file as the entry key, and specifying the exception message. Use %<number> where the input parameters should be placed. Note that <number> is their index+1 in parameters array list.

Code Block
languagexml
titletranslation_eng.properties
collapsetrue
...<properties>
	<entry key="key_com_crm_exception_accounts_invalidaccountcreditperiodexception">Invalid Credit period %1 based on definition (%2 % 3)accountterminationexception">You are not allowed to terminate the accounts receivable %1. This is only allowed for Active or Suspended accounts.</entry>
	.
	.
	.
</properties>

      4. Throw the exception.

Code Block
themeEclipse
languagejava
titleInvalidAccountCreditPeriodException.java
collapsetrue
public void validateTermination(CRMDOAccountReceivable account)  throws Exception, AccountTerminationException{
		
		if (account.getLifeCycleState()==null || 
		   (!account.getLifeCycleState().equals(AccountReceivableLifeCycleState.ACTIVE) && 
			!account.getLifeCycleState().equals(AccountReceivableLifeCycleState.SUSPENDED)))
		{
		    throw new AccountTerminationException(getCRMSession(), account.getNumber());
		}
		...
}

Question 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 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.

...

Expand
titleQuestion Message

Image Added

In order for a question message to appear on screen, two java methods should be created.

  1. Create the java method that will display the question.
    1. Use showConfirmQuestion method of com.crm.process.CRMUI class to display the confirmation question. 
      1. Define the method to be called if the user clicks 'YES' (class name, method name, question code) and message parameters, as input parameters for showConfirmQuestion method.
    2. Continue implementing what should be executed right after postPayment method, if the user clicks 'YES', or right after the user clicks 'NO'.
  2. Create the java method that will be called if the user clicks 'YES'
Code Block
themeEclipse
languagejava
titleCRMUIPaymentBean.java
collapsetrue
...

	/**
     * Posts payment. (Sets posted date, generates transaction number, performs allocations).
     * 
     * @param payment        a payment to post
     * @return                updated payment
     * @throws Exception
     */
    public CRMDOPayment postPaymentButton(CRMDOPayment payment) throws Exception {
        
		//parameters: interface class, function and question message
        showConfirmQuestion(
                "CRMUIPayment",
                "postPayment",
                "CONFIRM_FINANCIAL_TRANSACTION_SAVED_AS_POSTED",
                new String[]{"Payment"});
        
        return payment;
    }

...

 

Later on, we observe below, the method named showConfirmQuestion which is implemented in the CRMUI parent class, where the question object and options are defined and lastly the message is been showed.

 

Code Block
themeEclipse
languagejava
titleshowConfirmQuestion method
collapsetrue
	/**
     * Displays a confirmation question on the UI with options Yes/No. 
     * If the Yes option is chosen then the specified function is called, otherwise it does nothingPosts payment. (Sets posted date, generates transaction number, performs allocations).
     * 
     * @param beanName - the class name of the function to be called if the Yes option is chosenpayment		a payment to post
      * @param functionName - the name of the function to be called if the Yes option is chosen
     * @param questionCode - the code of the question message as it is defined in the messages metadata file
     * @param messageParameters - the parameters of the question message@return				updated payment
     * @throws Exception
     */
    protectedpublic voidCRMDOPayment showConfirmQuestionpostPayment(String beanName, String functionName, String questionCode, String[] messageParametersCRMDOPayment payment) throws Exception {
        
        Question question = new Question(getCRMSession(),questionCode,messageParameters, getCRMSession().getRealPath(), getOrganisationID())	return processFinTransactionBean.postPayment(payment);
        
        QuestionOption optionA = new QuestionOption("Yes", beanName, functionName, new String[]{"[[getDTO]]"}, new String[]{"java.lang.Object"}, "replace", "read");
        QuestionOption optionB = new QuestionOption("No", beanName, "echoDto", new String[]{"[[getDTO]]"},
new
String[]{"java.lang.Object"}, "replace", "read");
        
        question.addOption(optionA);
        question.addOption(optionB);
        
        showQuestion(question);
    }

 

Moreover, as in the previous example, the code of the question message must be defined in messages of metadata file whilst the expression key must also be mentioned in labels file as follows:

 

      3. Define the question code in metadata messages file.

Code Block
themeEclipse
languagejava
titlemessages.xml
collapsetrue
 	<message>
         <code>CONFIRM_FINANCIAL_TRANSACTION_SAVED_AS_POSTED</code>
         <expression>key_confirm_financial_transaction_saved_as_posted</expression>
         <description>Confirm Action</description>
    </message>

      4. Define the question in the English translation properties file, by using the expression tag key defined in metadata messages file as the entry key, and specifying the question message. Use %<number> where the message parameters should be placed. Note that <number> is their index+1 in message parameters array list.

Code Block
themeEclipse
languagejava
titletranslation_eng.properties
collapsetrue
 	<entry key="key_confirm_financial_transaction_saved_as_posted">%1 is going to be saved as Posted. Do you wish to continue?</entry>

 

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

 

Informational Messages

Expand
titleQuestion Informational Message

Image Removed

 

Warning Messages

The last example is about showing warning messages and as previously the same procedure is been followed. The following example constructing a warning message about the license on its interface class. Firstly, an InfoMessage object is created and some parameters are parsed. The first parameter is the crmSession, second the code of the message, third are some message parameters, then the path of the session and the organization id as follows. Lastly, the showInfoMessage method is called to demonstrates the warning message on the screen by parsing the message details.

 

Image Added

In order for n informational message to appear on screen, you have to 

  1. Create an instance of com.crm.process.InfoMessage object, defining the session, message code, message parameters, session real path, and organisation id as shown below.
  2. Use showInfoMessage method of com.crm.process.CRMUI class to display the message on screen.
Code Block
themeEclipse
languagejava
titleInfoMessage saveGeneralSetting method
collapsetrue
		InfoMessage/**
infoMsg	 =* new InfoMessage(getCRMSession(),
                "LOGOUT_INFO_MSG", 
         Saves a general setting.
	 * 
	 * @param generalSetting - the general setting to save
	 * @return the saved general setting	
	 * @throws Exception
	 */
    public  new String[]{"Payment"},
 GeneralSetting saveButton(GeneralSetting generalSetting) throws Exception {
    	
    	systemSettingBean.validateGeneralSettings(generalSetting);
    getCRMSession().getRealPath(),	systemSettingBean.saveGeneralSettings(generalSetting);
    	
    	InfoMessage infoMsg=new InfoMessage(getCRMSession(),"LOGOUT_INFO_MSG", null,     getCRMSession().getRealPath(), getOrganisationID());
    	
    	showInfoMessage(infoMsg);
    	
    	return generalSetting;
    }

 

Once again, the code of the warning message must be defined in messages of metadata file whilst the expression key must also be mentioned in labels file, as follows.

 

    3. Define the message code in metadata messages file.

Code Block
themeEclipse
languagejava
titlemessages.xml
collapsetrue
	<message>
        <code>LOGOUT_INFO_MSG</code>
        <expression>key_logout_info_msg</expression>
        <description>Logout to apply the changes</description>
    </message>

      4. Define the message in the English translation properties file, by using the expression tag key defined in metadata messages file as the entry key, and specifying the question message. Use %<number> where the message parameters should be placed. Note that <number> is their index+1 in message parameters array list.

Code Block
themeEclipse
languagejava
titletranslation_eng.properties
collapsetrue
	<entry key="key_logout_info_msg">Please logout and login again so thethat changes will be applied.</entry>

 

Then, on the following screen is illustrated the warning message, when a field is been changed.

 

Expand
titleWarning Message

Image Removed

 

...