Versions Compared

Key

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


Panel
nameidblue0

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

What does this section cover?

Table of Contents

...

Get the session object

To retrieve the current CRM Session 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.

Code Block
titleRetrieve CRM Session
collapsetrue
 public CRMDO copy(CRMDO dto)
{
	CRMSession session = getCRMSession();
	...
}

...

Using the session object

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

Code Block
titleExample 1 - Logged In User
collapsetrue
 public CRMDO copy(CRMDO dto)
{
	CRMSession session = getCRMSession();
	if( dto instanceof CUSTOMCRMDORentalTypeProduct)
	{
		CUSTOMCRMDORentalTypeProduct oldProductproduct = (CUSTOMCRMDORentalTypeProduct) dto;
		CUSTOMCRMDORentalTypeProduct newProduct = (CUSTOMCRMDORentalTypeProduct)oldProduct.clone();
		newProduct.setCreatedDate(getCurrentDate());
		newProduct.product.setCreatedByUnit(session.getUnit());
		newProductproduct.setCreatedByUser(ejbSessionsession.getLoggedUser());
		newProductproduct.setUpdatedByUnit(nullsession.getUnit());
		newProductproduct.setUpdatedByUser(null);
		newProduct.setUpdatedDate(nullsession.getLoggedUser());
	}
}


Code Block
titleExample 2 - Formatting Settings
collapsetrue
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;
}

...

Code Block
titleExample 3 - General Settings
collapsetrue
protected CRMDOContactInformation setDefaultResidenceCountry(CRMDOContactInformation contact) throws Exception {
		
	GeneralSetting generalSettings = getCRMSession().getGeneralSettings();
		
	if (generalSettings!=null)
	{
		contact.setResidenceCountry(generalSettings.getDefaultCountry());
	}
	
	return contact;
}
Code Block
titleExample 4 - Translation
collapsetrue
public LookupBuilder getAllowedProductOptions(CUSTOMCRMDORentalType rentalType) throws Exception {
         
       ArrayList<CRMDO> allowedProducts = rentalTypeProductBean.loadAllowedProducts(rentalType);
       if(allowedProducts!=null)
		{
			Iterator<CRMDO> iter = allowedProducts.iterator();	
			while (iter.hasNext())
			{
				CUSTOMCRMDORentalTypeProduct rtProduct = (CUSTOMCRMDORentalTypeProduct)iter.next();
				if(rtProduct!=null && rtProducT.getProduct()!=null)
				{
					String value = rtProducT.getProduct().getCode();
					if(rtProducT.getProduct().getType()!=null)
					{
						value += "(" + getCRMSession().getTranslation(rtProducT.getProduct().getType().getName()) + ")";
					}
					builder.build(rtProducT.getProduct().getId(),value); 
				}
			}
		} 
        return builder;
}