Showing posts with label MS CRM 2016. Show all posts
Showing posts with label MS CRM 2016. Show all posts

Microsoft Dynamics CRM Code Standards

Me and my friend Grigory Syomin created code standards we stick to.

We are glad to share document we did and hope that this document will be usefull to you as start point for your own standards. Here are links to doc and pdf.

Plugin to set records' names automatically

On each projects there are entities we can't force user to set names for (because it is needless). However it is good approach if all you records has names, especially if you have to choose these records in lookups.

I use plugins to set names of such entities. To simplify development of such plugins I did a base class and want to share it with you.

Let me show you example of the plugin which is based on SetNamePluginBase (base plugin) I share below.

using ExitoConsulting.Plugins.Base;
using Microsoft.Xrm.Sdk;

namespace ExitoConsulting.Plugins
{
    public class OwnerSetName : SetNamePluginBase
    {
        protected override string GetName(Entity entity, IPluginExecutionContext context, IOrganizationService service)
        {
            var fullName = entity.GetAttributeValue("ec_fullname");
            var clientId = entity.GetAttributeValue("ec_clientid");

            if(string.IsNullOrEmpty(fullName))
            {
                return null;
            }

            var name = fullName;
            if(!string.IsNullOrEmpty(clientId))
            {
                name = name + string.Format(" - {0}", clientId);
            }

            return name;
        }
    }
}