Panel |
---|
|
CRM Session holds information about the logged in user, the server, the database and the general and formatting settings.
What does this section cover? |
...
Getting the session object
To retrieve get 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 |
---|
title | Retrieve CRM SessionGetting the session object |
---|
collapse | true |
---|
|
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.
Code Block |
---|
title | Example 1 - Logged In User |
---|
collapse | true |
---|
|
public CRMDO copy(CRMDO dto)
{
CRMSession session = getCRMSession();
if( dto instanceof CUSTOMCRMDORentalTypeProduct)
{
CUSTOMCRMDORentalTypeProduct oldProductproduct = (CUSTOMCRMDORentalTypeProduct) dto;
CUSTOMCRMDORentalTypeProduct newProduct = (CUSTOMCRMDORentalTypeProduct)oldProduct.clone(product.setCreatedByUnit(session.getUnit());
newProductproduct.setCreatedDatesetCreatedByUser(getCurrentDatesession.getLoggedUser());
newProductproduct.setCreatedByUnitsetUpdatedByUnit(session.getUnit());
newProductproduct.setCreatedByUsersetUpdatedByUser(ejbSessionsession.getLoggedUser());
}
} |
Code Block |
---|
title | Example 2 - Formatting Settings |
---|
collapse | true |
---|
|
public BigDecimal getTotalAmount(ArrayList<CRMDO> rentalItems) {
{
BigDecimal totalAmount = new BigDecimal(0);
...
newProduct.setUpdatedByUnit(null
FormattingSetting formattingSetting = getCRMSession().getFormattingSettings();
Integer numberOfDecimalDigits = formattingSetting.getNumberOfDecimalDigits();
if (numberOfDecimalDigits!=null)
{
totalAmount = totalAmount.setScale(numberOfDecimalDigits.intValue(), BigDecimal.ROUND_HALF_UP);
newProduct.setUpdatedByUser(null);
newProduct.setUpdatedDate(null}
return totalAmount;
} |
Code Block |
---|
title | Example 3 - General Settings |
---|
collapse | true |
---|
|
protected CRMDOContactInformation setDefaultResidenceCountry(CRMDOContactInformation contact) throws Exception {
GeneralSetting generalSettings = getCRMSession().getGeneralSettings();
if (generalSettings!=null)
{
contact.setResidenceCountry(generalSettings.getDefaultCountry());
}
return contact;
} |