Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 79901

RetrieveMutipleRequest is not available in Visualstudio environment, why?

$
0
0

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.

My question is  why isn't the RetrieveMultpleRequest compiled

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

RetrieveUnpublishedMultipleRequest rmreq1 = newRetrieveUnpublishedMultipleRequest(); // 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!.");
                    }
                }
            }
        }

 


Viewing all articles
Browse latest Browse all 79901

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>