How to access CRM 4.0 settings programmatically?
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 开发者_C百科the General (and, possibly, other) CRM settings from my code?
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
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.
精彩评论