Notifications
Announcements
No record found.
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.
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); } } } }
Hello,
What is the error message that you are receiving? Can you please share it?
Where is your plugin registered?
opp1["opportunityid"] = myLookupId.Id;
this part should be:
opp1["opportunityid"] = myLookupId;
(You need to set a EntityReference, not the GUID)
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Tom_Gioielli 108 Super User 2025 Season 2
Jimmy Passeti 50 Most Valuable Professional
Gerardo RenterÃa Ga... 49 Most Valuable Professional