Skip to end of banner
Go to start of banner

Use CRM Session

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

CRM Session holds information about the logged in user, the server, the database and the general and formatting settings.

What does this section cover?

Get the session object

To retrieve the current session object you have to use getCRMSession() method which is implemented in com.crm.businessobject.CRMBase super class. Note that all CRMBO, CRMUI, CRMProcess and CRMAPIBean classes extend CRMBase.

Retrieve CRM Session
 public CRMDO copy(CRMDO dto)
{
	CRMSession session = getCRMSession();
	...
}

Using the session object

After getting the session object, you can use it to get information about the logged in user, the server, the database and the general and formatting settings.

Example 1 - Logged In User
 public CRMDO copy(CRMDO dto)
{
	CRMSession session = getCRMSession();
	if( dto instanceof CUSTOMCRMDORentalTypeProduct)
	{
		CUSTOMCRMDORentalTypeProduct product = (CUSTOMCRMDORentalTypeProduct) dto;

		product.setCreatedByUnit(session.getUnit());
		product.setCreatedByUser(session.getLoggedUser());
		product.setUpdatedByUnit(session.getUnit());
		product.setUpdatedByUser(session.getLoggedUser());
	}
}
Example 2 - Formatting Settings
public BigDecimal getTotalAmount(ArrayList<CRMDO> rentalItems) {
{
	BigDecimal totalAmount  = new BigDecimal(0);
	...
	
	FormattingSetting formattingSetting = getCRMSession().getFormattingSettings();
	Integer numberOfDecimalDigits = formattingSetting.getNumberOfDecimalDigits();

	if (numberOfDecimalDigits!=null)
	{
		totalAmount  = totalAmount.setScale(numberOfDecimalDigits.intValue(), BigDecimal.ROUND_HALF_UP);
	}
 
	return totalAmount;
}
Example 3 - General Settings
protected CRMDOContactInformation setDefaultResidenceCountry(CRMDOContactInformation contact) throws Exception {
		
	GeneralSetting generalSettings = getCRMSession().getGeneralSettings();
		
	if (generalSettings!=null)
	{
		contact.setResidenceCountry(generalSettings.getDefaultCountry());
	}
	
	return contact;
}
  • No labels