Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

RetrieveMutipleRequest is not available in Visualstudio environment, why?

Posted on by 135

I have trying to write my first CRM plug in from my visual studio 2015 which has Microsoft 365 Developer toolkit installed, and the plug in is created from the template as my screenshot below.

plugin1.png

My question is  why isn't the RetrieveMultpleRequest compiled

RetrieveMultipleRequest rmreq = new RetrieveMultipleRequest(); // not compiled

RetrieveUnpublishedMultipleRequest rmreq1 = new RetrieveUnpublishedMultipleRequest(); // the similar method of this is compiled.

I know these example codes used in CRM 4.0, Does that mean the  RetrieveMultipleRequest method is retired? then what is his replacement method.

The following is the sample plugin code I want to implement from internet : http://mileyja.blogspot.com/2011/04/instantiating-service-object-within.html

 public void Execute(IServiceProvider serviceProvider)
        {
            
            // Obtain the organization service reference.

            IPluginExecutionContext context = (IPluginExecutionContext)
               serviceProvider.GetService(typeof(IPluginExecutionContext));

            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
          

            // The InputParameters collection contains all the data passed in the message request.
            if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
            {
                // Obtain the target entity from the input parmameters.
                Entity entity = (Entity)context.InputParameters["Target"];

                if (entity.LogicalName == "contact")
                {
                    if (entity.Attributes.Contains("address1_city") == false)
                    {
                        

                        RetrieveMultipleRequest rmreq = new RetrieveMultipleRequest();
                        RetrieveMultipleResponse rmresp = new RetrieveMultipleResponse();
                        
                        
                        QueryExpression query = new QueryExpression()
                        {
                            EntityName = "systemuser",
                            ColumnSet = new ColumnSet(true),
                            Criteria = new FilterExpression
                            {
                                FilterOperator = LogicalOperator.And,
                                Conditions = 
                                {
                                    new ConditionExpression
                                    {
                                        AttributeName = "systemuserid",
                                        Operator = ConditionOperator.Equal,
                                        Values = { context.UserId.ToString() }
                                    }
                                }
                            }
                        };

                        rmreq.Query = query;
                        rmresp = (RetrieveMultipleResponse)service.Execute(rmreq);
                        Entity user = (Entity)rmresp.EntityCollection.Entities[0];

                        entity.Attributes.Add("address1_city", context.UserId.ToString() + ": " + user.Attributes["fullname"]);
                    }
                    else
                    {
                        // Throw an error, because account numbers must be system generated.
                        // Throwing an InvalidPluginExecutionException will cause the error message to be displayed in a dialog of the Web application.
                        throw new InvalidPluginExecutionException("Bad, Naughty Plug-in, Don't do that!.");
                    }
                }
            }
        }

 

*This post is locked for comments

  • Verified answer
    Sreevalli Profile Picture
    Sreevalli 3,256 on at
    RE: RetrieveMutipleRequest is not available in Visualstudio environment, why?

    Hi,

    It is not recommended to use RetrieveMultipleRequest, rather you can use RetrieveMultiple. see the modified code below. if your intention is not just to learn RetrieveMultiple, then you can switch to single retrieve as you already having record Guid, see commented code.

      QueryExpression query = new QueryExpression()
                    {
                        EntityName = "systemuser",
                        ColumnSet = new ColumnSet(true),
                        Criteria = new FilterExpression
                        {
                            FilterOperator = LogicalOperator.And,
                            Conditions =
                                    {
                                        new ConditionExpression
                                        {
                                            AttributeName = "systemuserid",
                                            Operator = ConditionOperator.Equal,
                                            Values = { context.UserId.ToString() }
                                        }
                                    }
                        }
                    };
                    
                    EntityCollection rmresp = service.RetrieveMultiple(query);
                    Entity user = rmresp.Entities[0];
                   // Entity user = service.Retrieve("systemuser", context.UserId, new ColumnSet(true));


  • Peter Cong Profile Picture
    Peter Cong 135 on at
    RE: RetrieveMutipleRequest is not available in Visualstudio environment, why?

    perfect, this is correct, it works after adding Microsoft.Xrm.Sdk.Messages  

  • Verified answer
    David Jennaway Profile Picture
    David Jennaway 14,063 on at
    RE: RetrieveMutipleRequest is not available in Visualstudio environment, why?

    I think you're just missing a namespace reference.

    RetrieveUnpublishedMultipleRequest is in the Microsoft.Crm.Sdk.Messages namespace, while RetrieveMultipleRequest is in the Microsoft.Xrm.Sdk.Messages namespace. Just add the following at the top of the code:

    using Microsoft.Xrm.Sdk.Messages;


  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: RetrieveMutipleRequest is not available in Visualstudio environment, why?

    Hello,

    According to the SDK this should work - docs.microsoft.com/.../gg327661(v%3Dcrm.8)

    I would recommend to use service.RetrieveMultiple(query) instead - this is usual practice nowadays.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans