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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

how to retrieve account name from contact lookup using plugin

(0) ShareShare
ReportReport
Posted on by 20

Hi

On create of a case record,i want to retrieve contact lookup value from case form  and get the Account name associated with that contact.

then set that account name to a custom company_lookup field using Plugin only.

1781.1376.Capture.PNG 

Please help!!

Thank You!

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mahadeo Matre Profile Picture
    17,021 on at
    RE: how to retrieve account name from contact lookup using plugin

    Hi,

    You need to write pre-create plugin, and you can get contact id from plugin input parameters..

    then using organization service you can retrieve company lookup and set that value to in plugin context.

  • Tanvi Profile Picture
    20 on at
    RE: how to retrieve account name from contact lookup using plugin

    Hi Mahadeo,

    Thanks for your response!

    Actually I am new to plugins. Could you please give me some reference ?

    As per my Requirement,Case is  automatically getting created from an  Email activity.And i need to set company name of contact(sender) on case form using Plugin.

     So I am registering the plugin for 'Case' entity,on Create message.

    After getting the contact lookup field Guid from case form, how can i retrieve company lookup of that contact in my Plugin.

    Any Example?

  • Suggested answer
    Mahadeo Matre Profile Picture
    17,021 on at
    RE: how to retrieve account name from contact lookup using plugin

    Hi..

    Here are some examples on how to write plugin..

    crmbook.powerobjects.com/.../developing-a-plug-in

    docs.microsoft.com/.../sample-create-basic-plugin

    community.dynamics.com/.../195080

    community.dynamics.com/.../276002

  • Tanvi Profile Picture
    20 on at
    RE: how to retrieve account name from contact lookup using plugin

    After getting the contact lookup field Guid from case form, How can i retrieve company lookup of that contact in my Plugin.????

    How can I do that?

  • Verified answer
    Mahadeo Matre Profile Picture
    17,021 on at
    RE: how to retrieve account name from contact lookup using plugin

    public void Execute(IServiceProvider serviceProvider)

       {

           try

           {

               IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

               IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

               IOrganizationService service = factory.CreateOrganizationService(context.UserId);

               IOrganizationService systemService = factory.CreateOrganizationService(null);

               if (context.Depth > 1)

                   return;

               if (context.InputParameters.Contains("contactid"))

               {

                   Guid contactid = new Guid(context.InputParameters["contactid"].ToString());

                   ColumnSet cols = new ColumnSet(new string[] { "accountid" });

                   //retrieve contact record to get account.  

                   Entity ocontact = (Entity)service.Retrieve("contact", contactid, cols);

                   EntityReference refAccount = (EntityReference)ocontact["accountid"];

                   context.OutputParameters["accountid"] = refAccount;

               }

           }

           catch (Exception ex)

           {

               throw new InvalidPluginExecutionException("Plugin Error: " + ex.Message);

           }

       }

  • Tanvi Profile Picture
    20 on at
    RE: how to retrieve account name from contact lookup using plugin

    Thank you sir :)

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#2
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans