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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

CREATE DYNAMICS CRM PLUGIN TO ASSIGN A dummy customer DURING CASE Creation

(0) ShareShare
ReportReport
Posted on by 6
Need to add the cases to dummy customer when ever the customer  open the new cases 
I have the same question (0)
  • Suggested answer
    pavanmanideep Profile Picture
    1,331 on at
    Hi,
     
    You can use this piece of code for your requirement..
     
    using System;
    using Microsoft.Xrm.Sdk;
    namespace YourNamespace
    {
        public class AssignCaseToDummyCustomerPlugin : IPlugin
        {
            public void Execute(IServiceProvider serviceProvider)
            {
                // Obtain the tracing service
                ITracingService tracingService =
                    (ITracingService)serviceProvider.GetService(typeof(ITracingService));
                // Obtain the execution context from the service provider
                IPluginExecutionContext context = (IPluginExecutionContext)
                    serviceProvider.GetService(typeof(IPluginExecutionContext));
                // Check if the plugin is triggered by the creation of a new case
                if (context.InputParameters.Contains("Target") &&
                    context.InputParameters["Target"] is Entity &&
                    context.PrimaryEntityName == "incident" &&
                    context.MessageName == "Create")
                {
                    // Get the new case record
                    Entity newCase = (Entity)context.InputParameters["Target"];
                    // Check if the case has a customer (account/contact) associated with it
                    if (newCase.Attributes.Contains("customerid"))
                    {
                        // Get the customer id
                        EntityReference customerRef = (EntityReference)newCase.Attributes["customerid"];
                        // Check if the customer is a contact
                        if (customerRef.LogicalName == "contact")
                        {
                            // Obtain the organization service
                            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
                            // Update the case to assign it to the dummy customer
                            Entity updatedCase = new Entity("incident");
                            updatedCase.Id = newCase.Id;
                            updatedCase["customerid"] = new EntityReference("account", Guid.Parse("YOUR_DUMMY_CUSTOMER_ID_HERE"));
                            service.Update(updatedCase);
                        }
                    }
                }
            }
        }
    }
     
    Hope this helps..
     
    If my response was helpful, please click 'Like.' To confirm the solution, mark it as 'Verified' to help others find right solutions. For further queries, feel free to reach out to me.
     
    Blog:https://ecellorscrm.com
     
    Cheers,
    PMDY
     
  • Suggested answer
    Pradeep Rai Profile Picture
    5,489 Moderator on at
    You can write Power Automate like below:
     
    Other option is workflow like below:
     

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
11manish Profile Picture

11manish 156

#2
ManoVerse Profile Picture

ManoVerse 153 Super User 2026 Season 1

#3
Zhilan Profile Picture

Zhilan 49

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans