views:

41

answers:

2

Some of the plugins I wrote (re)calculate various prices, and I used Math.Round to keep results accurate with the default 2 digit setting in CRM.

But I figured... what if a user decides to set his CRM to use a different precision?

So, I need to access the CRM settings programmatically, so that my functions can work with whatever setting the user chooses.

How would I go about accessing the General (and, possibly, other) CRM settings from my code?

A: 

Here is a nice trick you can use to figure this out...

Create a blank report with wizard, export it do RDP file and open it in Visual Studio. Inspect created datasets, one of them is called "DSNumberAndCurrencyInfo".

This is the query behind that dataset.

SELECT 
    DateFormat, DateFormat + ' ' + TimeFormat AS DateTimeFormat, 
    NumberLanguageCode, CalendarType, 
    NumberFormat_0_Precision, NumberFormat_1_Precision, 
    NumberFormat_2_Precision, NumberFormat_3_Precision, 
    NumberFormat_4_Precision, NumberFormat_5_Precision, 
    CurrencyFormat_0_Precision, CurrencyFormat_1_Precision, 
    CurrencyFormat_2_Precision, CurrencyFormat_3_Precision, 
    CurrencyFormat_4_Precision, CurrencyFormat_5_Precision
FROM
    dbo.fn_GetFormatStrings()

It means that there is a DB function available that will tell you various format setting of the user that executed the function.

You could also dig deeper and open the function, but you probably will not need to.

David Vidmar
Hmm... thanks for the answer, I was however hoping I could do without connecting to the CRM database on my own and use tools provided by the CRM SDK to do this task. Still, if nothing else is possible, then this will just have to do. ;)
Shaamaan
+1  A: 

Hi,

the settings of an user are stored in the usersettings entity. The settings of the organization are stored in the organization entity

However the settings for specific attributes are stored in the metadata (e.g. decimal with 4 digits precision). You have to use the Metadata service in combination with the RetrieveAttribute message which will return the AttributeMetadata for the attribute. For a CrmDecimal attribute it will be an instance of DecimalAttributeMetadata which has for example a property containing the configured precision.

hth

ckeller
Thanks! That's exactly what I needed. Now I feel kind of silly for not finding this myself.
Shaamaan