Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Plug-in Development

Posted on by 225

Hello everyone,

I need to write my very first plug-in. I am needing to get the number of related records on a the parent entity.  Basically the number of phone calls to an account. Unable to use a roll up field for this. 

Can someone point to some good tutorials on how to do this? 

*This post is locked for comments

  • Suggested answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Plug-in Development

    Hello,

    Apart from this I will suggest you to download CRM SDK, if you have not downloaded yet, which will give you good start. You can also look plugin development vedios in youtube:

    www.google.co.in/search;source=lnms&tbm=vid&sa=X&ved=0ahUKEwi1vers-sHWAhUHv48KHcx3AtIQ_AUICigB&biw=1366&bih=662

    Hope it will help.

    Thanks

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Plug-in Development

    No,

    That would be a function within the class for the entity that you are creating.

    Calling this function would return the number of records for the entity, based on the criteria that you would enter in the filter area.

    To get the exact query that you need, you can use fetch Xml builder from XRM Toolbox.

  • Jerry P. Profile Picture
    Jerry P. 225 on at
    RE: Plug-in Development

    Hi Aric,

    I am new to CRM development, where would I put this code at? As an event handler?

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Plug-in Development

    You can use the following sample code to get a count of record. This sample is based on the email entity:

            private int RetrieveEmailCount(Guid emailId)
            {
                int rc = 0;
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("<fetch distinct='false' mapping='logical' aggregate='true'> ");
                sb.AppendLine(" <entity name='email'> ");
                sb.AppendLine("  <attribute name='activityid' alias='email_count' aggregate='count'/> ");
                sb.AppendLine("  <filter type='and'>");

                sb.AppendLine("   <condition attribute='XXX' operator='eq' value='" + filterValue + "' /> ");
                sb.AppendLine("  </filter> ");
                sb.AppendLine(" </entity> ");
                sb.AppendLine("</fetch>");

                EntityCollection totalCount = service.RetrieveMultiple(new FetchExpression(sb.ToString()));
                if (totalCount.Entities.Count > 0)
                {
                    foreach (var t in totalCount.Entities)
                    {
                        rc = (int)((AliasedValue)t["email_count"]).Value;
                        break;
                    }
                }
                return rc;
            }

  • terrydashley Profile Picture
    terrydashley 5 on at
    RE: Plug-in Development

    Did you ever get an answer to this?

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans