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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Retrieving Team records with FetchXML

(0) ShareShare
ReportReport
Posted on by

I have the following bit of code in my plugin:

            string fetchXml =
                @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                    <entity name='team'>
                        <attribute name='name' />
                        <attribute name='teamid' />
                        <order attribute='name' descending='false' />
                        <filter type='and'>
                            <condition attribute='name' operator='eq' value='All Users' />
                        </filter>
                    </entity>
                </fetch>";


This is the fetch xml query I'm trying to use to grab a Team named "All Users".

I am executing the request like this:

            FetchExpression fetchExpressionXML = new FetchExpression(fetchXml);
            EntityCollection Teams;
            Teams = service.RetrieveMultiple(fetchExpressionXML);

Note that service is an IOrganizationService object.


This works if I try to pull an account instead of a team.  However, with a Team it fails 95% of the time.  A non-descript exception error is occurring during service.RetrieveMultiple(fetchEpressionXML).  On rare occasion it appears to be work, but this almost never happens.

Does anyone have any insight on what might be the problem?  Again, this method works if I'm querying accounts, so there seems to be something special about teams that makes this different.

*This post is locked for comments

I have the same question (0)
  • Mitch Milam Profile Picture
    on at

    What is the error?

  • bpoindexter Profile Picture
    on at

    Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: System.ServiceModel.CommunicationException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #102E8A04Detail:

    <OrganizationServiceFault xmlns:i="[View:http://www.w3.org/2001/XMLSchema-instance]" xmlns="[View:http://schemas.microsoft.com/xrm/2011/Contracts]">

     <ErrorCode>-2147204345</ErrorCode>

     <ErrorDetails xmlns:d2p1="[View:http://schemas.datacontract.org/2004/07/System.Collections.Generic]" />

     <Message>System.ServiceModel.CommunicationException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #102E8A04</Message>

     <Timestamp>2016-06-11T14:44:25.7081841Z</Timestamp>

     <InnerFault i:nil="true" />

    Unfortunately this error is very generic and unhelpful.

    Is it possible that retrieving the records through and IOrganizationService object instead of a OrganizationServiceProxy object could be a problem?

    FYI the step I have registered with this plugin fires on creation of a new user. The plugin is then supposed to find a specific team and add the new user to it. The context of the step is the organizations Administrator account (this is the deployment admin account that created the org in the first place. It has the system administrator role)

  • Mitch Milam Profile Picture
    on at

    Here is the error. What does your org service code look like?

     80044307  

    -2147204345

    AsyncCommunicationError

    A communication error occurred while processing the async operation.

  • bpoindexter Profile Picture
    on at

    Here is the beginning of my main execution procedure, showing the declaration and creation of the organization service object.  I am also creating a tracing service here...don't think that would matter, but you never know when little details do, so I've left everything in including my code comments.

            public void Execute(IServiceProvider serviceProvider)
            {
                //Create a tracing service.  This will make error messages more descriptive
                //and ease debugging
                ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
    //Get the execution context tracingService.Trace("Creating Execution Context."); IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
    //Create an organization service tracingService.Trace("Creating Organization Service Factory."); IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
    //The user ID used here should be in the User under which the plugin is fired //During plugin registration, I will specify an Admin user so that the service will have //permissions to alter teams //This is NOT the same User that we are adding to a team //This is only the user the plugin is running as tracingService.Trace("Creating Organization Service using organization service factory. The user context is user with guid " + context.UserId); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);


  • Mitch Milam Profile Picture
    on at

    are you sure the error is actually coming from the Fetch statement? I don't see anything wrong with the code I've seen so far.  What does the actually team assignment look like?

    Also, in regard to functionality?  Are you actually adding the new user to an All Users team or was that just for demo purposes? If that it actually what is happening, can you not just use the team created for the organization, which is automatically maintained?

  • bpoindexter Profile Picture
    on at

    To answer your first question, I am reasonable sure that the RetrieveMultiple statement is at fault.  I am using the tracing service to post a message to the trace log at every step.  If I use the fetch statement to fetch teams, the last item I get in the trace log is that it's calling RetrieveMultiple to get teams.  If I change the XML query to retrieve accounts, it works fine, and I can even have the trace utility print the names of the accounts in the log, where as when retrieving teams the last trace I get is that it's retrieving the teams and I get no name printouts to go with it.

    For what it's worth, I've also attempted to RetrieveMultiple using a QueryExpression instead of FetchXML with the same results.

    The team assignment code looks like this:

            //This method adds the user to the All Users team
            public void AddUserToTeam(ITracingService tracingService, IOrganizationService service, Entity User, Entity Team)
            {
                tracingService.Trace("Entity is a user.  User's name is " + User.Attributes["firstname"] + " " + User.Attributes["lastname"]);
                tracingService.Trace("User's GUID is " + User.Id);
    //Create a request to add team members AddMembersTeamRequest request = new AddMembersTeamRequest();
    //Create an array consisting of the id of the user to add Guid[] MemberId = {User.Id}; request.TeamId = Team.Id; request.MemberIds = MemberId; service.Execute(request); }


    As to functionality...the automatically maintained teams won't work.  We are looking to implement separate business units for the divisions within our company, however, it is needed for us to have a single team that includes ALL users, regardless of which business unit they are part of.  The automatically maintained lists only automatically add users that are a member of the current business unit.

    The reason we want this is because certain accounts, which are not clients but are vendors, need to be shared among the whole company WITHOUT sharing all accounts of all kinds among the entire company.  These vendor accounts need to be owned by a team of which all users are a member, regardless of their business unit, and this is something I'd rather not have to maintain manually.

  • Community Member Profile Picture
    on at

    couple of options to try

    1) In your code check teamid is not default GUID

    2)  rule out this assumption of the issue originates from retrieving teamid by : either hardcoding the team id( this is just for your testing purpose only) or passing teamid as configuration data (unsecure config) during your plugin registration and add additional line of code to read unsecure config.

  • Suggested answer
    Hemant Kumar Sahu Profile Picture
    1,829 on at

    Hi Bpoindexter,

    I would suggest you,just debug you code and get your fetch xml how its generating and try to check in 'Fetch Xml Tester' using 'XRMToolbox'.

    Thanks
    Hemant

  • bpoindexter Profile Picture
    on at

    Mitch Milam,

    Let me add something else.  This error is inconsistent in how it appears.  Upon first run of the plugin, I get the following error, also pretty non-descript:

    Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Generic SQL error.Detail: 
    <OrganizationServiceFault xmlns:i="www.w3.org/.../XMLSchema-instance" xmlns="schemas.microsoft.com/.../Contracts">
      <ErrorCode>-2147204784</ErrorCode>
      <ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic" />
      <Message>Generic SQL error.</Message>
      <Timestamp>2016-06-14T14:54:29.649129Z</Timestamp>
      <InnerFault i:nil="true" />
      <TraceText i:nil="true" />
    </OrganizationServiceFault>
    
    

    Now, if I RDC to my CRM server, run the CRM Diagnostic Tool, and change something (doesn't matter what, turning on Dev Errors is good enough) and I run the plugin again, I get the error I detailed above.

    But it occurs to me that maybe the fetch isn't the problem, maybe the failure of the fetch is a result of whatever this error is.  Is there any way to get CRM or SQL server to give me something more detailed than this?

  • bpoindexter Profile Picture
    on at

    Hemant Sahu,

    I ran my Fetch XML code in the Fetch XML Tester in XRMToolbox.  There was no errors and it did retrieve the records I expected it to retrieve.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans