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

Getting record in CRM Online through CRM 365 Plugin

$
0
0

Hi, i need to retrieve records in CRM Online through plugin which registered in CRM 365 On-Premise. This record will be used to fill some fields in CRM 365 On-Premise.

I have created console application that retrieve records in CRM. In the Console Application, i used ClientCredentials to connect with CRM. And it's success to retrieve some records in dynamics CRM.

Something like this:

ClientCredentials credit = new ClientCredentials();
                credit.UserName.UserName = "crmadmin";
                credit.UserName.Password = "password";
                service = new OrganizationServiceProxy(new Uri("mycompany/.../Organization.svc"), null, credit, null);

I use those code inside my plugin. So my plugin looks like:

public void Execute(IServiceProvider serviceprovider)
        {
            IPluginExecutionContext context = (IPluginExecutionContext)serviceprovider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory servicefactory = (IOrganizationServiceFactory)serviceprovider.GetService(typeof(IOrganizationServiceFactory));
             service = servicefactory.CreateOrganizationService(context.UserId);

            if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
           {

                Entity ent = (Entity)context.InputParameters["Target"];

                if (ent.LogicalName != "opportunity")
                    return;

                //Getting PresalesId of the records
                //Presales ID on crm 365 will be used for parameters while retrieve  records in crm online
                string Presid = ent.GetAttributeValue<String>("new_presalesid");
                try
                {
                    ClientCredentials credentials = new ClientCredentials();
                    credentials.UserName.UserName = "Jaya@mlptcare.onmicrosoft.com";
                    credentials.UserName.Password = "CrmAdmin365";
                    ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
                    service = new OrganizationServiceProxy(new Uri("https://mlptcare.api.crm5.dynamics.com/XRMServices/2011/Organization.svc"), null, credentials, null);

                    QueryExpression qxc = new QueryExpression { EntityName = "opportunity", ColumnSet = new ColumnSet(true) };
                    qxc.Criteria.AddCondition("new_presalesid", ConditionOperator.Equal, Presid);
                    qxc.ColumnSet = new ColumnSet(true);

                    EntityCollection colect = service.RetrieveMultiple(qxc);

                    foreach (Entity e in colect.Entities)
                    {
                        topic = e.GetAttributeValue<String>("name");
                        estClose = e.GetAttributeValue<DateTime>("estimatedclosedate");
                        estRev = e.GetAttributeValue<Money>("estimatedvalue");
                        rating = e.GetAttributeValue<String>("new_rating");
                        recurring = e.GetAttributeValue<String>("new_recurring");
                        dealReg = e.GetAttributeValue<String>("new_dealregistration");
                        perGP = e.GetAttributeValue<Decimal>("new_percentgp");
                        optyNum = e.GetAttributeValue<Decimal>("new_optynumber");
                        amName = e.GetAttributeValue<String>("new_amname");

                    }


                    string mix = topic + estClose + estRev + rating + recurring;

                    throw new InvalidPluginExecutionException("Result of Quert : " + mix);
                }
                catch (Exception ex)
                {
                    throw new InvalidPluginExecutionException(ex.Message);
                }


After registered this  plugin using plugin registration tool. On create Message, Isolation mode: None. I tried to make a new record on the CRM 365. But then comes an error message: 

Metadata contains a reference that cannot be resolved

I'm sure that i can access this link

"mlptoffice.api.crm5.dynamics.com/.../Organization.svc

also i used the  SDK for CRM 365 version 8.2

If you ever retrieve record in other crm through plugin. Could you give me some advice how to do that ? Some code snippet would be better.

Thanks


Viewing all articles
Browse latest Browse all 46379

Trending Articles



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