Tuesday, 13 May 2014

CRM 2013 Utilize Custom Action as Dynamics Error Message

Many times during my project development and implementation, I have requirement to Alert user if they have to input some field, those some fields sometimes is not mandatory during the Form, but it is mandatory for our Logic.

For example, in the Account entity creation or update.

- In Contact entity, City is not mandatory for some accounts type.

- If Contact Role is an Influencer, then their address will be very important to you, including City, State, and Country to complete your Addresses.

- If Contact Role is an Owner, then same as well, their complete address will be mandatory.

- If Contact Roles is not an Influencer nor an Owner then, Address fields will be only Optional or Recommendation.

So, you cannot make the Address fields as Mandatory for all of Situation, yes, you can achieve this by using JS or Business Rules, but remember that if you Form script, then let’s say user do inserting using backend such as other application or using excel import wizard, then you are forced to use Plugin to validate. Lets say you have to implement this in Lead, Account, and Contact, then this is applied to Create and Update Messages, right.

So, what possible situation is by creating a plugin that calls this :


And I put them to all of my coding.
That’s fine, yes that’s Okay, and it worked.

Then what happened if my user said : Hi, I don’t want to use that messages.
Often, developer use their own way and words to spread an alert, that is not acceptable by some business users because this is till blur and unclear.

So, let’s say first you say : “Please input ‘blabla’ Value!!”, then user said, please change to : “‘blabla’ Value Cannot be Blank”, then change again to more polite command : “Hi Sir/Madam, Please don’t forget to fill the ‘blabla’ Value. Thanks”, then what will you do?

Okay, you have to change all of your Code, it is fine since you just copy paste, but you have various word for ‘blabla’ right? It can be City, State, Country, Fax, Mobile Phone, Membership ID, or whatever you have. So, yes, this is sometimes annoying.

Then, what I did in CRM 2011 is I create an entity, similar to Configuration entity to store my own Error Messages

Key Name
Key Value
Parameter Type
Please input ‘City’ Value
Error Message
Error message if City Blank
Please input ‘State Value
Error Message
Error message if State Blank
Please input ‘Country Value
Error Message
Error message if Country Blank

Imagine you have many fields, then you have to change all of the Key Value.
It is okay, maybe you can utilize the string.format Message to make the City, State, Country, etc as dynamic value.

But, do you know that in CRM 2013, you can utilize custom action to make your own Error Message more dynamic? This is the more elegant idea to work with Action to get some dynamic Error Message.
If you have known familiar with Action, please refer to this link :


Here are the steps :

1. Create an Action


2. Define your Arguments

Input : FieldName – String – Required – Input
Output : MessageOutput – String – Required – Output

Define Argument custom action 2_thumb

3. Define your Steps by Assigning the Value


In this step, using your Input Argument you can create a Dynamic Output, using that FieldName input argument as dynamic value, based on what you pass as input.

4. After define your arguments and Activate your Custom Action


5. Using .NET in Plugin you can call your Custom Action

Early Bound


Late Bound

Call that action in your Plugin

Here is the code
        public string ExecuteCustomAction_PleaseInputValue(IOrganizationService service, string strFieldName)
            tfp_Action_PleaseInputValueRequest request = new tfp_Action_PleaseInputValueRequest()
                FieldName = strFieldName

            tfp_Action_PleaseInputValueResponse response = service.Execute(request) as tfp_Action_PleaseInputValueResponse;
            //Processing of response
            return response.MessageOutput;

        public string ExecuteCustomAction_PleaseInputValue(IOrganizationService service, string strInputParameter, string strInputParameterValue, string strOutputParameter)
            OrganizationRequest req = new OrganizationRequest("tfp_Action_PleaseInputValue");
                    req[strInputParameter] = strInputParameterValue;
                    //execute the request
                    OrganizationResponse response = service.Execute(req);
            return response[strOutputParameter].ToString();

For Reference :


To generate Action in Early Bound Class :


6. Here is your result

When City is Blank


7. Here if you want to change your Error Message, just change it :

- Go back to your Action
- Deactivate first


- Change the steps


8. Here is your result


Enjoy it!

For your information, for importing Action it can be a big deal in CRM 2013, at least until Rollup 2
Please refer to this :


Hope it helps!


  1. Being new to the blogging world I feel like there is still so much to learn. Your tips helped to clarify a few things for me as well as giving..
    Mobile Marketing Services
    Mobile Marketing Companies
    SMS Marketing

  2. I have read your blog its very attractive and impressive. I like your blog salesforce Online Training Hyderabad

  3. You're really something special. vidmate and You're so thoughtful Looking For More Posts

  4. Hello there. I discovered your blog by the use of Google while looking for a comparable topic, your website came up. It appears good. I’ve bookmarked it in my google bookmarks to come back then.
    best hospital management system software

  5. This comment has been removed by the author.

  6. Avail this bargaining tool in your e-commerce storebargainingtool

  7. Try Best Website Development Digital Marketing Mobile App Development Serviceswordpressdevelopmentservices


My Name is..