Sign up ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

In the Contact entity, I have the following attributes

Preferred email - A read only field of type Email
Personal email 1 - An email field
Personal email 2 - An email field
Work email 1 - An email field
Work email 2 - An email field
School email - An email field
Other email - An email field
Preferred email option - An option set with the following values
  {Personal email 1, Personal email 2, Work email 1, Work email 2,
   School email and Other email). 

None of the above mentioned fields are required.


When user picks a value from Preferred email option, we copy the email address available in that field and apply the same in the Preferred email field.


The Solution Architect suggested that we implement the above requirement as a Workflow. The reason he provided was - most of the times, these values are to be populated by an external website and the data is then fed into CRM 2011 system. So, when they update Preferred email option via a Web Service call to CRM, the WF will run and updated the Preferred email field.

My argument / solution

  • What will happen if I do not pick a value from the Preferred email Option Set? Do I set it to any of the email addresses that has a value in it? If so, what if there is more than one of the email address fields are populated, i.e., what if Personal email 1 and Work email 1 is populated but no value is picked in the Option Set?
  • What if a value existed in the Preferred email Option Set and I then change it to NULL?
  • Should the field Preferred email (where the text value of email address is stored) be set to Read Only?

    • If not, what if I have picked Personal email 1 in the Option Set and then edit the Preferred email address text field with a completely new email address
    • If yes, then we are enforcing that the preferred email should be one among Personal email 1, Personal email 2, Work email 1, Work email 2, School email or Other email [My preference would be this]
  • What if I had a value of in the personal email 1 field and personal email 2 is empty and choose value of Personal email 1 in the drop down for Preferred email (this will set the Preferred email field to and later, I change the value to Personal email 2 in the Preferred email. It overwrites a valid email address with nothing. I agree that it would be highly unlikely that a user will pick Preferred email as Personal email 2 and not have a value in it but nevertheless it is a possible scenario, isn’t it?

  • What if users typed in a value in Personal email 1 but by mistake picked Personal email 2 in the option set and Personal email 2 field had no value in it.


  1. The field Preferred email option should be a required field
  2. A JS should run whenever Preferred email option is changed. That JS function should set the relevant email field as required (based on the option chosen) and another JS function should be called (see step 3).
  3. A JS function should update the value of Preferred email with the value in the email field (as picked in the option set).
  4. The JS function should also be run every time someone updates the actual email field which is chosen in the option set.

The guys who are managing the external website should update the Preferred email field - surely, if they can update Preferred email option via a Web Service call, it is easy enough to update the Preferred email right?


Which is a better method? Should it be written as a JS or a WorkFlow?
Also, whose responsibility is it to update the Preferred email field when the data flows from an external website?

I am new to CRM 2011 but have around 6 years of experience as a CRM consultant (with other products). I do not come from a development background as I started off as a Application Support Engineer but have picked up development in the last couple of years.

share|improve this question

2 Answers 2

You should use a Plugin for this kind of stuff, there is no reason to enforce this on the front end. What if someone updates the entity via the web-service API?

Specifically you should set the plug in to fire on Create or Update of Contact.

share|improve this answer
Which part of it should be done as a Plugin? The entire functionality - even the checks to ensure that if you pick a value of Personal email 2 in the Preferred email option set, there should be a value in Personal email 2? Why? That would require a call to the server right? Would it not be better if that is avoided? Regarding what if someone updates the entity via the Web-Service API, I guess we make them update both the fields - i.e., if someone updates the Preferred email option set then it is their responsibility to update the Preferred email field as well. – Kanini Mar 11 '13 at 13:06
The validation if a value exists (in my scenario it is from an external website) will be the responsibility of that website developer. – Kanini Mar 11 '13 at 13:07
Updating of data based on conditions (2 & 3) – Morons Mar 11 '13 at 13:17
@Kanini to be completely honest I don't fully understand what its you are trying to do. I suggest you read up on plugins and consider them as a third option. – Morons Mar 11 '13 at 13:19

Three "rules" I'd recommend for customizing Dynamics CRM:

  • Workflows are terrible. Avoid them like the plague.
  • Use JavaScript for customizations that apply only to interactions via the UI/Outlook and/or that require immediate feedback.
  • Use Plugins for everything else.

So, in your case, even though I don't fully understand your requirements, I'd recommend a plugin because it'll be triggered by hits to the webservice; not just by hits to the UI/Outlook.

Unless you need some validation to throw an exception if the given email address is invalid, you're looking at a post-create/update event that performs a simple update. Set the preferred email field to the value in that of the preferred email option and run an update. (Can't provide more detail than that, I'm afraid. I haven't actually written a CRM plugin for a few years!)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.