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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

To find the contact entity matching with email address in Event Registration Form in Dynamics 365 Portal

(0) ShareShare
ReportReport
Posted on by

We have "Event Registration form" in Dynamics 365 - Customer Self Service Portal. When the user provides his information (First & Last Names, email address and State), before saving this record it should search for contacts that are matching the email address entered in "Event Registration form" and set the contact reference to "Related Contact" attribute. Similarly for "Related Lead" also. 

Have used JavaScript to achieve this in Dynamics CRM Event Registration form using xrmservicetoolkit. But the same is not possible in Portal.

Please help me to resolve this issue.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    Somehow i was able to find solution for this issue.  Here is the solution using plugin. In the below function i have used QueryExpression to find the Contact and Lead matching the email address provided in the input parameter to the method.

    // calling GetRelatedEntity method in main Execute method.

    if (entity.LogicalName == "new_eventregistration")

                    {                  

                        if (entity.Attributes.Contains("new_email"))

                        {                        eventRegEmail = entity.Attributes["new_email"].ToString();

                            // To check the Contact for matching email address

                            #region contact lookup

                            EntityCollection ContactsEC = GetRelatedEntity(orgService, "contact", "emailaddress1", eventRegEmail, new ColumnSet("fullname", "contactid","emailaddress1"));

                            if (ContactsEC.Entities.Count >= 1)

                            {   entity.Attributes["new_relatedcontact"] = new EntityReference("contact", ContactsEC.Entities[0].Id) ; // setting the reference of contact to Event Registration - Related Contact field                          

                            }

                            #endregion contact lookup 

                            #region lead lookup

                            else  {

                                EntityCollection LeadsEC = GetRelatedEntity(orgService, "lead", "emailaddress1", eventRegEmail, new ColumnSet("fullname", "leadid", "companyname"));

                                if (LeadsEC.Entities.Count >= 1)

                                { // setting the reference of contact to Event Registration - Related Lead field 

                                  entity.Attributes["new_relatedlead"] = new EntityReference("lead", LeadsEC.Entities[0].Id);}

                               }                      

                             #endregion lead lookup

                        }

                    }

            // Generic method to query Contact and lead based on the parameters supplied

            private static EntityCollection GetRelatedEntity(IOrganizationService orgSvc, string entityName, string searchItem, string searchItemValue, ColumnSet colSet)

            {

                QueryExpression query = new QueryExpression

                {

                    EntityName = entityName,

                    ColumnSet = colSet,

                    Criteria = new FilterExpression

                    {

                        Conditions ={

                         new ConditionExpression{

                            AttributeName = searchItem,

                            Operator = ConditionOperator.Equal,

                            Values = { searchItemValue }

                            }

                        }

                    }

                }; return orgSvc.RetrieveMultiple(query);

             }

            #endregion lookup method

         }

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans