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 :
Dynamics 365 Community / Forums / Sales forum / Plugins in Dynamics 365
Sales forum

Plugins in Dynamics 365

(0) ShareShare
ReportReport
Posted on by

Hello,

I want to make a plugin that creates a contact with the same name of account when an account is created in Dynamics 365 using plugins.

Categories:
I have the same question (0)
  • Suggested answer
    Reece Campbell Profile Picture
    217 on at

    Does this need to be a plugin for some reason? You could do this with a simple workflow (either synchronous or asynchronous) by creating the process on the account entity and triggered on create. The step would simply create a new record (contact) with the correct fields set (assuming that would be the Last Name field as that is a required field). This would achieve your stated requirement.

    Alternatively you can use this sample (Sample: Create a basic plug-in) as the basis for your plugin and instead of creating a task you create a contact and remove the if statement after the comment below (this code sets the regarding field of the created task in this sample):

    // Refer to the account in the task activity.

    Hope that helps

  • Community Member Profile Picture
    on at

    Hello,

    Actually i want to create a contact with the same name as account using plugins and for that i need to fetch the account name in plugin and put it into the contact name field , but i am not getting how to fetch the value of account name in plugins.

  • Suggested answer
    Reece Campbell Profile Picture
    217 on at

    I would highly recommend you read the SDK documentation on Plugins to get a good understanding of exactly what is happening but you can find the specific info on how to retrieve data from the actual entity the event is triggered on (in this case the account) from this article: Understand the data context passed to a plug-in.

    The specific section of that data context article you should check is Input and output parameters which shows how to get the entity from the context and then you would get the name via the entity object as below (very rough and untested code):

    // The InputParameters collection contains all the data passed in the message request.
    if (context.InputParameters.Contains("Target") &&
        context.InputParameters["Target"] is Entity)
    {
        // Obtain the target entity from the input parameters.
        Entity entity = (Entity)context.InputParameters["Target"];

    }

    // Access the Account Name

    string accountName = entity["name"];

  • Suggested answer
    CRMJetty Profile Picture
    3,512 on at
    Hello User,

    Users can create a plugin that will automatically create a contact record in CRM whenever any new account record is created in CRM.
     
    Refer this blog for the steps to apply field-level security in the system field in CRM.

     
    Thanks & Regards    
    I hope it helps,
    Thanks.
    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Portal.
     
     
  • Sandhya Rabadiya Profile Picture
    16 on at
    Hi User,

    To write and register a plugin in Dynamics 365 to create a contact when an account is created in the system, follow these steps:

    1. Create a new plugin project. You can use Visual Studio to create a class library-type project in the .net framework for plugin in c#. After that, you need to add references for Microsoft SDK mentioned below:
         Microsoft.Crm.Sdk.Proxy.dll
         Microsoft.Xrm.Sdk.dll
         Microsoft.Xrm.Tooling.Connector.dll
    2. Implement the IPlugin interface. Your plugin class must implement the IPlugin interface, which defines a single IPlugin.Execute method.
    3. Write the code to create a contact. In the IPlugin.Execute method, write the code to create a new contact record. You can use the IOrganizationService interface to create the contact record.
    Here is an example of a plugin that creates a contact when an account is created:

                                   public class CreateContactPlugin : IPlugin
                                  {
                                      public void Execute(IServiceProvider serviceProvider)
                                      {
                                          // Get the IOrganizationService interface.
                                          IOrganizationService service = (IOrganizationService)serviceProvider.GetService(typeof(IOrganizationService));

                                          // Get the entity that is being created.
                                          Entity entity = (Entity)serviceProvider.GetService(typeof(Entity));

                                          // Create a new contact record.
                                          Entity contact = new Entity("contact");
                                          contact["lastname"] = entity.Attributes["name"];
                                          contact["telephone1"] = entity.Attributes["telephone1"];

                                          // Create the contact record.
                                          service.Create(contact);
                                      }
                                  }

    4. Register the plugin. To register the plugin, you can use the Plug-in Registration Tool or the Power Platform CLI.
    5. Test the plugin. Once the plugin is registered, you can test it by creating a new account record. If the plugin is working correctly, a new contact record will be created automatically.
    To register the plugin, you can use the Plug-in Registration Tool:
    1. Open the Plug-in Registration Tool and sign in with environment credentials.
    2. Click the Register New Assembly button.
    3. Browse to the plugin assembly and click the Open button.
    4. Click the Load Assembly button.
    5. Expand the assembly node and right-click the (Plugin) CreateContactPlugin.
    6. Select Register New Step.
    7. In the Register New Step dialog box, select the following values:
            1. Message: Create
            2. Primary Entity: Account
            3. Event Pipeline Stage of Execution: PostOperation
            4. Execution Mode: Asynchronous
    Click the Register button.
    Once the plugin is registered, it will be triggered whenever an account record is created. The plugin will create a new contact record with the same name and telephone number as the account record.

    Hope this helps!

    Please mark verified if answer 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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Sales

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans