locked
how to retrieve the records at one go based on owning user or owning team in mscrm 2011 using fetch xml RRS feed

  • Question

  • I have to retrieve the country records under particular bu.  but country is related to bu throw owning user or owning team.

    how to retrieve the country records under particular bu base on owner id(User/Team)?


    hari
    Wednesday, December 14, 2011 11:56 AM

All replies

  • hi hari,

    You can use Advanced Find to build query and then use Download Fetch Xml command to get the fetch xml to use your query, with required changes.

    then refer sdk to learn the query execution, please refer an example from sdk.

    // Retrieve all accounts owned by the user with read access rights to the accounts and 
    // where the last name of the user is not Cannon. 
    string fetch2 = @"
       <fetch mapping='logical'>
         <entity name='account'> 
            <attribute name='accountid'/> 
            <attribute name='name'/> 
            <link-entity name='systemuser' to='owninguser'> 
               <filter type='and'> 
                  <condition attribute='lastname' operator='ne' value='Cannon' /> 
               </filter> 
            </link-entity> 
         </entity> 
       </fetch> "; 
    
    EntityCollection result = _serviceProxy.RetrieveMultiple(new FetchExpression(fetch2));
    
    foreach (var c in result.Entities)
       {
       System.Console.WriteLine(c.Attributes["name"]);
       }
    
    



    Thomas T(MCBMSS) If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Wednesday, December 14, 2011 1:17 PM
  • if  i have owner as one of team, then how to handile both user/team as owners in a single fetch.

    presently using two fetc calls.

     public const string f1 = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                                                                  <entity name='aon_country'>
                                                                    <attribute name='aon_country' />
                                                                    <attribute name='ownerid' />
                                                                    <attribute name='aon_countrycode' />
                                                                    <attribute name='aon_countryid' />
                                                                    <order attribute='aon_country' descending='false' />
                                                                    <filter type='and'>
                                                                      <condition attribute='aon_countrycode' operator='eq' value='{0}' />
                                                                    </filter>
                                                                    <link-entity name='systemuser' from='systemuserid' to='owninguser' alias='aa'>
                                                                      <filter type='and'>
                                                                        <condition attribute='businessunitid' operator='in'>
                                                                          <value uitype='businessunit'>{1}</value>
                                                                        </condition>
                                                                      </filter>
                                                                    </link-entity>
                                                                  </entity>
                                                                  </fetch>";
            public const string f2 = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                                                                  <entity name='aon_country'>
                                                                    <attribute name='aon_country' />
                                                                    <attribute name='ownerid' />
                                                                    <attribute name='aon_countrycode' />
                                                                    <attribute name='aon_countryid' />
                                                                    <order attribute='aon_country' descending='false' />
                                                                    <filter type='and'>
                                                                      <condition attribute='aon_countrycode' operator='eq' value='{0}' />
                                                                    </filter>
                                                                      <link-entity name='team' from='teamid' to='owningteam' alias='aa'>
                                                                      <filter type='and'>
                                                                        <condition attribute='businessunitid' operator='in'>
                                                                          <value uitype='businessunit'>{1}</value>
                                                                        </condition>
                                                                      </filter>
                                                                    </link-entity>
                                                                  </entity>             
                                                                </fetch>";

     

     

     

     

    Finally i want to have single fetch xml instead of above 2.


    hari
    Thursday, December 15, 2011 8:35 AM