Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenated / Calculated Columns in Dynamics CRM View

I am new to MS Dynamics and I would like to know if there is a way of adding column to a view within that is a concatenation of some other columns, for example:

Firstname + ' ' + Lastname As Fullname

There doesn't seem like there is an obvious (elegant) solution to this, all the suggestions I have seen suggest using javascript to maintain an new attribute.

Taken one step further, if I want to derive or calculate a column from another column for example a person's age from their date of birth, this would need to be calculated on the fly when view loads, correct? Again I can't immediately see a way to provide this simple functionality with the CRM framework. Perhaps I am missing something?

Any advice would be much appreciated.

like image 964
bigtv Avatar asked Sep 08 '10 16:09

bigtv


2 Answers

You're not missing anything. There is NOT an elegant solution to your problem. If you want it in a view you're going to need to add a custom column to display it.

If its truly computed (storing a fixed value in the database could be stale, as in your age example) then you'll need to add a plug-in on the post step of a Fetch message, parse the XML to determine if your entity is being returned, parse out the attributes which should be computed, compute the value, and then insert your computed attribute into the result xml.

Lets say you're not displaying the date of birth field in the view (you just want to display the age), then you're also going to have to have a plug-in on the pre step of the Fetch Message, parse the XML to determine if your entity is the one being fetched, determine if hte age column is being returned, and if so, inject the computation basis columns into the column set being returned.

Note that these plugin steps are NOT executed if you use the Filtered View's in SSRS reports, so you'd have to compute the age in TSQL in those cases. I don't think you'd ever be able to display the age column in CRM-created wizard reports (you can't get TSQL in here and the plugins won't run).

Given all that if you have something that CAN be fixed (concatentation), I would compute it in a create/update plugin for that entity and store it in a custom attribute (Fullname). In that case the attribute will just work for grid views, all flavors of reporting, etc.

like image 108
John Hoven Avatar answered Sep 16 '22 21:09

John Hoven


There is nothing like computed columns in Dynamics CRM. benjynito is right about using plugins, that is a viable solution.

But if it is enough to calculate the field to be displayed on a form, I usually use JavaScript to "fake" an attribute.

To give you an idea how to do it, here is a snippet of code where I use jQuery to insert label and readonly textbox in order to display parent records field value (phone number in my case).

// create label
$("#ad_contactid_c").next().next().find("label").text("Contact Phone:");
// create textbox
var phoneNumber = $(document.createElement("input")).addClass("ms-crm-Text ms-crm-ReadOnly").attr("contentEditable", "false").attr("id", "d_phoneNumber");
$("#ad_contactid_c").next().next().next().append(phoneNumber);
// fill textbox value
$("#d_phoneNumber").val(phone);
like image 21
David Vidmar Avatar answered Sep 20 '22 21:09

David Vidmar