plug-in to update an arecord and assign it to the user

Proposed Answer plug-in to update an arecord and assign it to the user

  • Tuesday, April 24, 2012 11:12 AM
     
     

    hello everyone i had requirement to create an a plug-in the scenario is when user assign a record in record if the field assignedto="designer" i want to change it to 'CSR"

    created "assign" message and post-operation on the plug-in but when debug the plug-in it is not executing the step coming to inputparameter and out of the loop an am understanding want to do guys if you have solution please help me code is here

    ////////////////plug-in code

    private string assigned;
            public void Execute(IServiceProvider serviceprovider)
            {
                IPluginExecutionContext context = (IPluginExecutionContext)serviceprovider.GetService(typeof(IPluginExecutionContext));


    if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity )
               {
                    Entity  entity = (Entity)context.InputParameters["Target"];
                    if (entity.LogicalName == "lead" && context.MessageName == "Assign")
                    {
                       Entity  lead=new Entity();
                        if (entity.Attributes.Contains("new_assignedto"))
                        {
                            assigned = (string)entity.Attributes["new_assignedto"];
                        }
                        if (assigned == "Designer")
                        {
                            lead["new_assignedto"] = "CSR";
                            IOrganizationServiceFactory servicefactory = (IOrganizationServiceFactory)serviceprovider.GetService(typeof(IOrganizationServiceFactory));
                            IOrganizationService service = servicefactory.CreateOrganizationService(context.UserId);
                            service.Update(lead);
           


    ms crm

All Replies