Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

on Creation of User, i need to write a plugin to create a contact with that user full name

$
0
0

on Creation of User, i need to write a plugin to create a contact with that user full name

may i know how to do this in MS CRM 2013?

thanks in advance....

Please find below code:

          

 public void Execute(IServiceProvider sericeProvider)
        {
            IPluginExecutionContext context = (IPluginExecutionContext)sericeProvider.GetService(typeof(IPluginExecutionContext));

            IOrganizationServiceFactory factory = (IOrganizationServiceFactory)sericeProvider.GetService(typeof(IOrganizationServiceFactory));

            IOrganizationService service = factory.CreateOrganizationService(context.UserId);

            if (context.InputParameters["Target"] is Entity && context.InputParameters.Contains("Target"))
            {
                Entity User = context.InputParameters["Target"] as Entity;

                string Username = User["fullname"].ToString();
                    Entity contact = new Entity("contact");
                    contact["lastname"] = Username;

                service.Create(contact);

            }

            }

i Resisted this plugin  in MS CRM by using plugin registration tool( message : CREATE ;Primary entity:Systemuser;on Post operation ) but it is not working for me ...



Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>