This section describes how error, warning, and question messages are created.
What does this section cover?
Error Messages
In order for an error message to appear on screen, a java exception must be created and thrown.
- Create the Exception class.
- All exception classes must extend com.crm.exception.CRMValidationException.
- 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.
- To create the exception method:
- Use com.crm.businessobject.CRMSession object as an input parameter and any other String input parameters needed.
- Put all String input parameters in a String ArrayList.
- Use setMessage method of com.crm.exception.CRMException class to construct the exception message.
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 value - the exception value
* @throws Exception
*/
public AccountTerminationException(CRMSession crmSession, String value) throws Exception {
super();
ArrayList<String> parameters = new ArrayList<String>();
parameters.add(value);
try
{
setMessage(this.getClass().getName().toUpperCase(), crmSession, parameters);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
2. Define the exception in the messages.xml file. Use a unique key for the expression tag. For more information on customising messages metadata, go to Customise Messages Metadata.
<messages>
<message>
<code>COM.CRM.EXCEPTION.ACCOUNTS.ACCOUNTTERMINATIONEXCEPTION</code>
<expression>key_com_crm_exception_accounts_accountterminationexception</expression>
<description>You are not allowed to terminate the accounts receivable. This is only allowed for Active or Suspended accounts.</description>
</message>
.
.
.
</messages>
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.
<properties>
<entry key="key_com_crm_exception_accounts_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.
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 order for a question message to appear on screen, two java methods should be created.
- Create the java method that will display the question.
- Use showConfirmQuestion method of com.crm.process.CRMUI class to display the confirmation question.
- 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.
- Continue implementing what should be executed right after postPayment method, if the user clicks 'YES', or right after the user clicks 'NO'.
- Create the java method that will be called if the user clicks 'YES'
...
/**
* 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;
}
/**
* Posts payment. (Sets posted date, generates transaction number, performs allocations).
*
* @param payment a payment to post
* @return updated payment
* @throws Exception
*/
public CRMDOPayment postPayment(CRMDOPayment payment) throws Exception {
return processFinTransactionBean.postPayment(payment);
}
...
3. Define the question code in metadata messages file.
<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.
<entry key="key_confirm_financial_transaction_saved_as_posted">%1 is going to be saved as Posted. Do you wish to continue?</entry>
In order for n informational message to appear on screen, you have to
- 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.
- Use showInfoMessage method of com.crm.process.CRMUI class to display the message on screen.
/**
* Saves a general setting.
*
* @param generalSetting - the general setting to save
* @return the saved general setting
* @throws Exception
*/
public GeneralSetting saveButton(GeneralSetting generalSetting) throws Exception {
systemSettingBean.validateGeneralSettings(generalSetting);
systemSettingBean.saveGeneralSettings(generalSetting);
InfoMessage infoMsg=new InfoMessage(getCRMSession(),"LOGOUT_INFO_MSG", null, getCRMSession().getRealPath(), getOrganisationID());
showInfoMessage(infoMsg);
return generalSetting;
}
3. Define the message code in metadata messages file.
<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.
<entry key="key_logout_info_msg">Please logout and login again so the changes will be applied.</entry>