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

Announcements

News and Announcements icon
Community site session details

Community site session details

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

Update the Third Party entities by Lookupfied through plugins

(0) ShareShare
ReportReport
Posted on by 10

Hi  all as  i  need to create the Lookupfield in Both Account entity and Contact entity with the oppurtunities entity. if the parent account entity value lookup has the same value in the child contact then the  same value in  oppurtunities entity  one field update automatically  through plugins. As I new to CRM Please can anyone guide me.

I have the same question (0)
  • Cathrin Profile Picture
    10 on at

    Hi As I new To Crm I wnat to i  need to create the Lookupfield in Both Account entity and Contact entity with the oppurtunities entity. if the parent account entity value lookup has the same value in the child contact then the  same value in  oppurtunities entity  one field update automatically  through plugins. As I new to CRM Please can anyone guide me.

    Here is my code and getting error in mylooup id 

     



    namespace updating_looupfield_from_third_entity
    {
        public class Class1 : IPlugin
    
        {
            private EntityReference myLookupId;
    
            public void Execute(IServiceProvider serviceProvider)
            {
                IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
                IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                IOrganizationService service = factory.CreateOrganizationService(context.UserId);
                ITracingService tracing = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
                Entity entity = (Entity)context.InputParameters["Target"];
                tracing.Trace("start traceing");
    
    
                Entity myEntityHavingLookup = service.Retrieve("account", entity.Id, new ColumnSet(true));
                
                   
                    myLookupId = myEntityHavingLookup.GetAttributeValue("new_accountlooukup");
    
                    QueryExpression acc = new QueryExpression("contact");
                    acc.ColumnSet = new ColumnSet(true);
                    acc.Criteria.AddCondition("new_contactlookup", ConditionOperator.Equal, myLookupId.Id);
                    EntityCollection Cont1 = service.RetrieveMultiple(acc);
    
                
    
                    if (Cont1.Entities.Count > 0)
                    {
    
                        Entity opp1 = new Entity("opportunity");
                        opp1["opportunityid"] = myLookupId.Id;
                        opp1["telephone1"] = "234555";
                        service.Update(opp1);
    
                    }
    
                
            }
    
    
        
        }
    }
    
    

  • Susana Carneiro Profile Picture
    Microsoft Employee on at

    Hello,

    What is the error message that you are receiving? Can you please share it?

    Where is your plugin registered?

  • Suggested answer
    Flydancer Profile Picture
    1,332 on at

    opp1["opportunityid"] = myLookupId.Id;

    this part should be:

    opp1["opportunityid"] = myLookupId;

    (You need to set a EntityReference, not the GUID)

  • Suggested answer
    Charles Abi Khirs Profile Picture
    3,569 on at

    Hello,

    You can use this:

    Entity myEntityHavingLookup = service.Retrieve("account", entity.Id, new ColumnSet(true));

    myEntityHavingLookup.Attributes["<YourLookupSchemaName>"] = new EntityReference("<LookupEntitySchemaName>", <LookupRecordGuid>);

    Where :

    1. YourLookupSchemaName : the schema name of the lookup field on your account entity

    2. LookupEntitySchemaName: the schema name of the entity for the lookup field

    3. LookupRecordGuid: the Guid of the record you want to set in the lookup field

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Hamza H Profile Picture

Hamza H 142 Super User 2026 Season 1

#2
Nagaraju_Matta Profile Picture

Nagaraju_Matta 128

#3
11manish Profile Picture

11manish 121

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans