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

Notifications

Announcements

No record found.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 108 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans