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)

How to create an OrganizationService instance from CrmServiceClient?

(0) ShareShare
ReportReport
Posted on by

I'm using the CrmServiceClient from the XRM tooling library in order to run queries on a CRM instance.

Does anyone know how I can cast the CrmServiceClient to an OrganizationService instance?

I need to create this instance in order to access the OrganizationService.Retrieve():
In order to do the following, where sourceService is an instance of OrganizationService -

sourceService.Retrieve(entityName, queueId, attributes);



At the moment I can run a query by casting the CrmServiceClient to an OrganizationServiceContext instance like this -

CrmServiceClient svcClient = Ctrl.CrmConnectionMgr.CrmSvc;

         
using (OrganizationServiceContext sourceContext = new OrganizationServiceContext(svcClient.OrganizationServiceProxy))
              

Q0 = (from q in sourceContext.CreateQuery("queue")
where q.GetAttributeValue<OptionSetValue>("emailrouteraccessapproval").Value == 2 ||
q.GetAttributeValue<OptionSetValue>("emailrouteraccessapproval").Value == 3

select q).ToList();







*This post is locked for comments

I have the same question (0)
  • Suggested answer
    KZee Profile Picture
    on at

    Hi,

    You have already got OrganizationServiceProxy (svcClient.OrganizationServiceProxy).

    You can simply use the following code to

    Var sourceService = (IOrganizationService) svcClient.OrganizationServiceProxy;

    And call sourceService.Retreive.

    Please mark the answer as verified if it was helpful.

  • Community Member Profile Picture
    on at

    Okay that has worked for the casting the IOrganizationService.

    But when I call Entity.SetAttributeValue<> within that code the compiler tells me "The non-generic method 'Microsoft.Xrm.Sdk.Entity.SetAttributeValue(string, object)' cannot be used with type arguments"

    Any ideas why that is, there is no option given for SetAttributeValue in intellisense?

    I normally use it like this:  

                               passedDownQueueEntity.SetAttributeValue<OptionSetValue>("emailrouteraccessapproval", EmailApprovalStates.Approved);

  • Suggested answer
    KZee Profile Picture
    on at

    SetAttributeValue is protected virtual method.

    You can use it if you Extend Entity class.

    The early bound classes generating using crmsvcutil uses this method because they inherit from Entity class.

    You can try.

    passedDownQueueEntity.Attributes["emailrouteraccessapproval"] = new OptionSetValue(1);

  • Suggested answer
    hicham Profile Picture
    215 on at

    string connectionString = @"AuthType=AD;Url=organization-url; Domain=domain; Username=username; Password=pwd";

    CrmServiceClient conn = new CrmServiceClient(connectionString);

    OrganizationServiceProxy _serviceProxy = conn.OrganizationServiceProxy;

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