web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Plugin : create a new record in an existing Entity

(0) ShareShare
ReportReport
Posted on by

Hello,

In a c# plugin, i try to create a new record in an existing entity.

What is the code to do that ?

Thanks,

Paul

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    you need to instantiate first an IOrganizationService

    IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
    IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

    and after create the record

    Entity newAccount = new Entity("account");
    newAccount["name"] = "TEST";
    service.Create(newAccount);


  • Community Member Profile Picture
    on at

    Thanks

  • Suggested answer
    Community Member Profile Picture
    on at

                               Entity goods = new Entity("goods");

                               goods .Attributes.Add("number", formNumber);

                               goods .Attributes.Add("comment", "");

                               goods .Attributes.Add("ownerid", owner);

                               try

                               {

                                   Guid guid = Service.Create(goods);

                               }

                               catch (Exception e)

                               {

                                   throw new InvalidPluginExecutionException("errors message\r\n" + e.Message, e);

                               }

  • Suggested answer
    Jeevarajan Kumar Profile Picture
    781 Most Valuable Professional on at

    Hi Paul,

    Below links will help you to understand the plugin development.

    Basics:

    http://crmbook.powerobjects.com/extending-crm/plug-in-development-and-workflow-extensions/plug-ins/developing-a-plug-in/

     

    In-depth about plug-in:

    https://msdn.microsoft.com/en-us/library/gg334724.aspx

     

    Develop using developer toolkit:

    https://www.youtube.com/watch?v=v3vie4hSE80

    Please mark this as answered if it is helpful.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans