locked
when ever we created a new entity and Generating account id but its not working why? RRS feed

  • Question

  • 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 =="account")
                    {
                        if (entity.Attributes .Contains ("accountnumber") == false )
                        {
                            Random rndgen = new Random ();
                           entity .Attributes .Add ("accountnumber",rndgen .Next ().ToString ());
                        }
                        else
                        {
                          throw new InvalidPluginExecutionException ("the account number only set by the system.");
                        }
                    }
                }

            }


            }
        }

    In this Code their  and registration also succedded

    but in crm form it can't working why ? 

                    thank u

                                 Naveen
    Monday, September 30, 2013 12:12 PM

All replies

  • Hi Naveen,

    Please make sure that your plugins stage of execution is "Pre-Operation".

    Thanks!

    • Proposed as answer by Kalim Khan Monday, September 30, 2013 4:32 PM
    Monday, September 30, 2013 12:19 PM