locked
Counting Sub-Accounts RRS feed

  • Question

  • I have searched and can't seem to find what I need.  Is there a way to count sub-accounts in Dynamics 4.0 and display that count into a text field?

    I have tried playing with http://crmxpg.nl/wp/2010/10/29/retrieve-all-sub-accounts-in-ms-crm/ and I cannot seem to get it to work for me.

    Thank you much for your help!

    Friday, March 9, 2012 3:35 PM

Answers

  • Download the SDK Daniel Cai JavaScript

    function getSubAccounts(){

    // Fetch all Sub Accounts records

    var Guid = //Guid of your current record

    var fetchXml =
    "<fetch mapping='logical'>" +
       "<entity name='account'>" +
          "<attribute name='accountid' />" +
          "<attribute name='firstname' />" +
          "<attribute name='your schema name for sub-accounts relationship' />" +
          "<filter>" +
             "<condition attribute='your schema name for sub-accounts relationship' operator='eq' value='" + Guid + "' />" +
          "</filter>" +
       "</entity>" +
    "</fetch>";

    var fetchedContacts = CrmServiceToolkit.Fetch(fetchXml);

    alert(fetchedContacts.length);

    }

    If you need any more information please tell me

    Thanks and Regards

    Blog: http://mubashersharif.blogspot.com
    Email: mubasher.sharif@gmail.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".


    Mubasher

    Saturday, March 10, 2012 5:29 PM
  • Hi,

    Whilst this is on the right track, it would be far more efficient to use the count aggregation in the fetchxml;

    http://msdn.microsoft.com/en-us/library/dd904030.aspx

    hth,

    Scott


    Scott Durow
    Read my blog: www.develop1.net/public
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Sunday, March 11, 2012 7:40 AM
    Answerer

All replies

  • Download the SDK Daniel Cai JavaScript

    function getSubAccounts(){

    // Fetch all Sub Accounts records

    var Guid = //Guid of your current record

    var fetchXml =
    "<fetch mapping='logical'>" +
       "<entity name='account'>" +
          "<attribute name='accountid' />" +
          "<attribute name='firstname' />" +
          "<attribute name='your schema name for sub-accounts relationship' />" +
          "<filter>" +
             "<condition attribute='your schema name for sub-accounts relationship' operator='eq' value='" + Guid + "' />" +
          "</filter>" +
       "</entity>" +
    "</fetch>";

    var fetchedContacts = CrmServiceToolkit.Fetch(fetchXml);

    alert(fetchedContacts.length);

    }

    If you need any more information please tell me

    Thanks and Regards

    Blog: http://mubashersharif.blogspot.com
    Email: mubasher.sharif@gmail.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".


    Mubasher

    Saturday, March 10, 2012 5:29 PM
  • Hi,

    Whilst this is on the right track, it would be far more efficient to use the count aggregation in the fetchxml;

    http://msdn.microsoft.com/en-us/library/dd904030.aspx

    hth,

    Scott


    Scott Durow
    Read my blog: www.develop1.net/public
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Sunday, March 11, 2012 7:40 AM
    Answerer
  • Thank you for your help!
    Tuesday, March 13, 2012 6:17 PM