Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Getting record in CRM Online through CRM 365 Plugin

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

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

Edited

 

I tried to use simplified connection using xrm.tooling. It's still failed but with different error message:

Could not load file or assembly 'Microsoft.Xrm.Tooling.Connector, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

 

string connstring = @"Url=https://office.crm5.dynamics.com; Username=admin@offiice.onmicrosoft.com; Password=office; authtype=Office365";
                CrmServiceClient conn = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connstring);
                _service = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;


And once again, when tested this on console application, its success to connect with CRM Online. But how to connect with other CRM through Plugin ??

*This post is locked for comments

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,076 on at
    RE: Getting record in CRM Online through CRM 365 Plugin

    See: msdn.microsoft.com/.../jj602970.aspx

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Getting record in CRM Online through CRM 365 Plugin

    I am done editing my question, there are simplified connection i used on console application and work. But fail when i used the simplified connection inside the plugin. I think there are something that can use on console application. But unable to use within plugin. Hope someone here can explain that :(

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Getting record in CRM Online through CRM 365 Plugin

    Yes, in the link i gave you. There are two references should be added. One of them is xrm.client.service.

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,076 on at
    RE: Getting record in CRM Online through CRM 365 Plugin

    In the link you provided it is  microsoft.xrm.sdk.client.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Getting record in CRM Online through CRM 365 Plugin

    Hi Nithya, to write simplified connection, microsoft.xrm.client is needed. And not microsoft.xrm.sdk.client. So i use xrm.tooling to create simplified connection. But still no luck. Another error appears when i test my plugin.

    take a look at my post, i will edit it

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,076 on at
    RE: Getting record in CRM Online through CRM 365 Plugin

    Hi Fikri,

    You just need to add Microsoft.Xrm.Sdk dll in Dynamics 365 SDK to the solution. It contains Microsoft.Xrm.Sdk.Client.

    For more details, see the link below.

    msdn.microsoft.com/.../gg334621.aspx

    Hope this helps.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Getting record in CRM Online through CRM 365 Plugin

    Hi Nithya,

    I can't find xrm.client for crm 365 in nuget package. In the link you gave me, they that i can use xrm.tooling. Also i added xrm.tooling insinde my solution. But still cant write using microsot.xrm.client;

    If i used xrm.client.dll from CRM 2015 SDK, is that fine ?

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,076 on at
    RE: Getting record in CRM Online through CRM 365 Plugin

    Hi Fikri,

    I suggest you to download Nuget package of this dll.

    See: social.microsoft.com/.../crm-2016-sdk-missing-microsoftxrmclientdll-missing

    Hope this helps.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Getting record in CRM Online through CRM 365 Plugin

    Hi nithya,

    i tried use the code in your following link. But still i am unable to connect to other CRM Online through plugin. Still face "Metadata contains reference that cannot be resolved".

    I am trying to use simplified connection as this link provide.

    But when i want to add reference: Microsoft.Xrm.Client.Services

    I am unable to find Microsoft.XRM.Client.dll inside CRM 365 SDK

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,076 on at
    RE: Getting record in CRM Online through CRM 365 Plugin

    Hi Fikri,

    Try to use the code in the following link.

    arunpotti.wordpress.com/.../retrieve-records-using-query-expression-c-sdk-in-crm

    Hope this helps you.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,375 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans