ttajic
12/2/2019 - 5:27 PM

plugin

using Microsoft.Xrm.Sdk;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SamplePlugin
{
    [CrmPluginRegistration("Create", 
    "contact", StageEnum.PreOperation, ExecutionModeEnum.Synchronous,
    "","SamplePlugin.ToUpper: Create of contact", 1, 
    IsolationModeEnum.Sandbox 
    ,Description = "SamplePlugin.ToUpper: Create of contact"
    ,Id = "3a5501a4-2514-ea11-a811-000d3a249c36" 
    )]
    public class ToUpper : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            IPluginExecutionContext context = (IPluginExecutionContext)
                serviceProvider.GetService(typeof(IPluginExecutionContext));

            var entity = (Entity)context.InputParameters["Target"];

            if (entity == null)
                return;

            var newName = entity.GetAttributeValue<string>("firstname")?.ToUpper();

            entity["firstname"] = newName;
        }
    }
}