Skip to main content

Notifications

Announcements

No record found.

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 
  • Suggested answer
    Pradeep Rai Profile Picture
    Pradeep Rai 5,480 Super User 2024 Season 2 on at
    CREATE DYNAMICS CRM PLUGIN TO ASSIGN A dummy customer DURING CASE Creation
    You can write Power Automate like below:
     
    Other option is workflow like below:
     
  • Suggested answer
    pavanmanideep Profile Picture
    pavanmanideep 1,329 on at
    CREATE DYNAMICS CRM PLUGIN TO ASSIGN A dummy customer DURING CASE Creation
    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
     

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,861 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,540 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans