Versions Compared

Key

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

...

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

 

Use CRM SessionUse CRM Session

After retrieving the CRM Session, 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 oldProduct = (CUSTOMCRMDORentalTypeProduct) dto;
		CUSTOMCRMDORentalTypeProduct newProduct = (CUSTOMCRMDORentalTypeProduct)oldProduct.clone();
		newProduct.setCreatedDate(getCurrentDate());
		newProduct.setCreatedByUnit(session.getUnit());
		newProduct.setCreatedByUser(ejbSession.getLoggedUser());
		newProduct.setUpdatedByUnit(null);
		newProduct.setUpdatedByUser(null);
		newProduct.setUpdatedDate(null);
	}
}
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;
}