Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Plugin code to auto populate the lookup filed

Posted on by Microsoft Employee

Hi

I didn't find the exact solution what  I am looking for , Just Let me elaborate the Question

I have 2  Custom entities in CRM

Customers And Events ( New_ Customers and New_Events)

In the event entity i have single line of text field Email and lookup field Email Address which is related to customers entity ,  

now the events are coming from external sources and saving in CRM ,once they saved i need the Email to be populated in Email Address so that i can see the customer events in customer entity sub grid called events or is there any possibility to filter sub grid records based on Email (single line text in crm). because i created a sub grid with all records  in Customer entity . Is there any possibility to do this 

I need urgent help, Please help me

THANKS

*This post is locked for comments

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Plugin code to auto populate the lookup filed

    In case you are trying to do this:

    - Create a new_customer lookup field on the event entity

    - On create of the event entity, run a plugin to populate that lookup

    That should work just fine.

    To populate the lookup, you can use a query expression:

    msdn.microsoft.com/.../microsoft.xrm.sdk.query.querybyattribute.aspx

    Have a look at this to see how it's done:

    stackoverflow.com/.../how-to-add-a-value-to-a-lookup-field

    And you'll need a plugin, of course..  There is some sample code here, but you'll need to combine it with the code from the links above:

    msdn.microsoft.com/.../gg594416.aspx

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Plugin code to auto populate the lookup filed

    Hi Divya,

    I am not sure which is your primary field in the Customer's entity, but I doubt it's the email address.

    Copying the email address to the lookup will not populate the lookup. You will need to get the referenced id of the customer record where the email address is the correct one. That can be done via web api, or if you want to do a plugin, you can write code on the Create or Update of the Event entity to update the customer lookup with the customer id (after retrieving it in your plugin code based on the email address).

    Saying that, it will not resolve your issue of displaying the information in the subgrid. Subgrid contents are based on related records. If I display a subgrid of in the event entity, that means all the subgrid records will have a lookup that points to the event entity.

    The only way you can filter it is by using the fetchXml/layoutXml option that I mentioned above. Since you are using CRM 2013 (based on your tag), this should work, but it might break on upgrading to Dynamics 365.

    Hope this helps.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Plugin code to auto populate the lookup filed

    Hi Aric ,

    Thanks for the reply ,

    I want to filter sub grid based on email id on customer form , i tried to do in the same way

    But the things not went well :(

    Is there any possibility to copy the lookup field from text field using plugin code . if the email address of 2 entities matches populate the lookup field . so that automatically sub grid will filter with matching records

    I need plugin code to populate the look up filed , i tried to do this js but my superior need it in plugin, so please help me to do this

    Thanks

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Plugin code to auto populate the lookup filed

    Hi Divya,

    Technically you should be able to design a fetchXml to filter the subgrid results based on a particular criteria

    Take a look at the following:

    community.dynamics.com/.../195546

    In the past, you used to get the subgrid object and assign the fetchXml and layoutXml:

    subgrid.SetParameter(“layoutxml”, “<layoutxml>”);

    subgrid.SetParameter(“fetchxml”, “<fetchxml>”);

    subgrid.control.Refresh();

    The issue that you might experience is that you cannot assign the subgrid to the document.getElement as this is unsupported. I have not recently tried this with Dynamics 365, but it is very possible that the above will still work, and instead of using

    var Subgrid = document.getElementById("Name of subgrid")

    you can use

    var Subgrid = Xrm.Page.getControl("Name of subgrid");

    Try it out, and hopefully this will help.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans