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.

  • Suggested answer
    Charles Abi Khirs Profile Picture
    3,569 on at
    RE: Update the Third Party entities by Lookupfied through plugins

    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

  • Suggested answer
    Flydancer Profile Picture
    1,332 on at
    RE: Update the Third Party entities by Lookupfied through plugins

    opp1["opportunityid"] = myLookupId.Id;

    this part should be:

    opp1["opportunityid"] = myLookupId;

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

  • Susana Carneiro Profile Picture
    on at
    RE: Lookup field update

    Hello,

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

    Where is your plugin registered?

  • Cathrin Profile Picture
    10 on at
    Lookup field update

    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);
    
                    }
    
                
            }
    
    
        
        }
    }
    
    

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 91

#3
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 78 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans