CRM 2011 - Query Number Cases Associated with the Customer (Contact record) from within a Case RRS feed

  • General discussion

  • Hi,

    In the Case entity there is a Customer field that I can associate with an Account or a Contact.  Currently in my application this will always be a contact, and I would like to find a way to do a count on the number of Cases that this contact record is associated with, once selected.  What I need to do is then display this number on the case form that indicates how many cases the selected contact record has association with.

    How can I do this in CRM 2011 using JavaScript?


    Monday, August 26, 2013 9:00 PM

All replies

  • Hi,

    You could use http://xrmsvctoolkit.codeplex.com and a aggregate fetchxml query. Something like:

    function fetchOperationCountSync()
        var count;
        var fetchXml =
    "<fetch distinct='true' mapping='logical' aggregate='true'>" +
    "    <entity name='contact'> " +
    "       <attribute name='contactid' alias='contact_count' aggregate='countcolumn' /> " +
    "    <link-entity name='incident' from='customerid' to='contactid' alias='aa'>" +
    "      <filter type='and'>" +
    "        <condition attribute='incidentid' operator='eq' uiname='test' uitype='incident' value='" + Xrm.Page.data.entity.getId() + "' />" +
    "      </filter>" +
    "    </link-entity>" +
    "    </entity> " +
            fetchXml: fetchXml,
            async: false,
            successCallback: function (result)
                count = result.entities[0]["contact_count"];
            errorCallback: function (error)
                throw error;
        return count;



    Scott Durow
    Blog www.develop1.net    Follow Me
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Wednesday, August 28, 2013 8:24 AM