Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Suggested answer

Can any one please help me this plugin

Posted on by 7
write a plugin,
On opportunity we already have access team in the form of Sales Team sub-grid. Whenever an opportunity is created, add 3 users in that sub-grid. Which 3 users to be added will be determined by the comma separated GUIDs in description field of opportunity entity.
  • Suggested answer
    Adrian Begovich Profile Picture
    Adrian Begovich 21,009 Super User 2024 Season 2 on at
    Can any one please help me this plugin
    Hi D365 Beginers,
     
    Here is a basic outline of a Dynamics 365 plugin in C# that you can use as a starting point. This plugin triggers when an Opportunity record is created, extracts three comma-separated GUIDs from the description field, and adds the corresponding users to a Sub-Grid on the Opportunity record.
    using System;
    using System.Linq;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Query;
    
    public class OpportunityCreatePlugin : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            // Obtain the execution context from the service provider.
            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
    
            // Obtain the organization service reference.
            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
    
            // 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"];
    
                // Verify that the target entity represents an opportunity.
                if (entity.LogicalName != "opportunity")
                    return;
    
                if (entity.Attributes.Contains("description"))
                {
                    // Get the description field value.
                    string description = entity.Attributes["description"];
    
                    // Split the description into GUIDs.
                    string[] guids = description.Split(',');
    
                    // Check if we have three GUIDs.
                    if (guids.Length == 3)
                    {
                        foreach (string guid in guids)
                        {
                            // Parse the GUID.
                            Guid userGuid = new Guid(guid.Trim());
    
                            // Create a reference to the user.
                            EntityReference userRef = new EntityReference("systemuser", userGuid);
    
                            // Create a new relationship entity record.
                            Entity relationship = new Entity("new_opportunity_sales_team");
                            relationship["new_opportunityid"] = entity.ToEntityReference();
                            relationship["new_userid"] = userRef;
    
                            // Create the relationship entity record.
                            service.Create(relationship);
                        }
                    }
                }
            }
        }
    }
  • Suggested answer
    Amit Katariya007 Profile Picture
    Amit Katariya007 8,150 Super User 2024 Season 1 on at
    Can any one please help me this plugin
    Hello User,
     
    Create a team. Add users to that team. Make sure when you create a opportunity, refer this team and add all the users in the opportunity access team.
     
     
    Thank you,
    Amit Katariya
  • Suggested answer
    Leah Ju Profile Picture
    Leah Ju Microsoft Employee on at

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 Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 229,918 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans