Calculated fields is one of the best new features and is indispensable for simple calculations. Keyword here is simple. Range of functions available in calculated fields is limited (though it continues to expand from release to release).
One of the “traditional” methods to add calculated field is to add a simple field and then create plugin on Retrieve and RetrieveMultiple messages. If field is part of the column list in either message, perform your voodoo and return the calculated value.
Smug developer that I am, that’s what I’ve done and reported to the customer. Who was rather disappointed with the result, as it turned out. Field was calculating fine but yielded very strange results when customer tried to build some charts using that field.
Humiliated, I’m happy to report that the following functionality won’t work for the fields calculated in Retrieve and RetrieveMultiple plugins:
- Sorting on the column in the listviews
- Using the column as aggregate value in charts
Come to think about it, that makes perfect sense. Sorting and aggregation is done as part of the T-SQL statement that runs on the SQL Server that has absolutely no clue about your plugin magic. As long as you and your customers are aware of these limitations, using plugins for calculations “on-the-fly” is perfectly fine.