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

Can any one please help me this plugin

(0) ShareShare
ReportReport
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.
I have the same question (0)
  • Suggested answer
    Leah Ju Profile Picture
    Microsoft Employee on at
  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Moderator on at
    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
    Adrian Begovich Profile Picture
    1,027 Moderator on at
    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);
                        }
                    }
                }
            }
        }
    }

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 165

#2
ManoVerse Profile Picture

ManoVerse 161 Super User 2026 Season 1

#3
Zhilan Profile Picture

Zhilan 49

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans