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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

plugin / count records for associated records

(0) ShareShare
ReportReport
Posted on by

hello

i have 2 table,and one of them is account and another is contact,

scenario : i want to count contacts that related to one contact and count contact which they are women

so i want total records that related to account and records that related to accounts and are women.

i wonder how can i write the code?

*This post is locked for comments

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

    With code, you'll need a query/filter expression or fetchxml.

    Filter Expression:

    msdn.microsoft.com/.../gg309410.aspx

    Fetchxml:

    msdn.microsoft.com/.../gg328117.aspx

    After fetching, you can run .Count or .Length or a similar expression to see how many records are returned from your query.

  • Verified answer
    Community Member Profile Picture
    on at

    You can easily search for these records using advance find. If you still want to use a plugin then do the below:

    1. When constructing the query to retrieve the contacts related to an account. Apply the condition where parent customer is the account. This should return all contacts associated with that account.

    2. Use the same query as above and add one more condition which will say that get those contacts which are female (whatever field you are using for gender). this will filter out the other genders and return only females.

  • Community Member Profile Picture
    on at

    sorry,i correct : i want to count contacts that related to one account and count contact which they are women

  • Community Member Profile Picture
    on at

    thank you

    please explain number 2

  • Suggested answer
    Community Member Profile Picture
    on at

    The number 2 tells you to add 2 conditions to the query. One is for the out of the box relationship between a contact and an account (account's lookup on contact). The second condition will be of gender. For example lets say you are using a dropdown field named as gender on contact. Then apply the condition to select only those contacts which have females option selected in gender field. Both of these conditions will ensure that you fetch only those contacts which are related to that account and are females.

  • Aileen Gusni Profile Picture
    44,524 on at

    Hi BSH

    Using aggregate will do

    *Fetch XML

    msdn.microsoft.com/.../gg309565.aspx

    dynamicsofdynamicscrm.com/.../aggregate-fetchxml-queries-for-dynamics-crm-20112013

    Or you get the query expression result as return, then you get count it

    Btw, if you use CRM 2015 you can just using rollup field.

    www.powerobjects.com/.../roll-up-fields-dynamics-crm-2015

    www.preact.co.uk/.../using-rollup-fields-in-microsoft-dynamics-crm-2015

    survivingcrm.com/.../crm-2015-rollup-fields-gotchas

    Hope this helps.

    Thanks

  • Rickard Norström Profile Picture
    on at

    Hi,

    You can write a plugin that Counts all Contacts related to account when you create a Contact related to the account or when you relate an existing Contact to an account. In case 2 you also need to Count all Contacts related to the previous account using a pre entity image (to get the previous account).

    Does that help?

    (this post is probably not needed)

    Regards

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans