locked
CRM 4.0 Conversion to CRM 2011 !!!! RRS feed

  • Question

  • How to do the same in CRM 2011 format????

    ICrmService crmService = context.CreateCrmService(false);

    systemuser callingUser = (systemuser)crmService.Retrieve(EntityName.systemuser.ToString(), context.UserId, new ColumnSet(new string[] { "domainname"

    }));


    hussain

    Sunday, January 20, 2013 12:01 PM

Answers

  • Hi Hussain,

    Try below code.

    public void Execute(IServiceProvider serviceProvider)
    {
             
    // Obtain the execution context from the service provider.
    IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
    IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

    IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);


    ColumnSet cols1 = new ColumnSet(new String[] { "domainname" });
    Entity bcd = (Entity)service.Retrieve("systemuser", context.UserId, cols1);



    }


    Chandan - http://mscrm-chandan.blogspot.in/ I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful !!!

    Monday, January 21, 2013 5:42 AM
  • Hello,

    Everything what Chandan wrote is correct except one line:

    instead of

    IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

    should be used

    IOrganizationService service = serviceFactory.CreateOrganizationService(null);


    Freelance Developer for Dynamics CRM 4.0/2011

    Monday, January 28, 2013 9:54 AM
    Moderator

All replies

  • Hi Hussain,

    Try below code.

    public void Execute(IServiceProvider serviceProvider)
    {
             
    // Obtain the execution context from the service provider.
    IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
    IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

    IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);


    ColumnSet cols1 = new ColumnSet(new String[] { "domainname" });
    Entity bcd = (Entity)service.Retrieve("systemuser", context.UserId, cols1);



    }


    Chandan - http://mscrm-chandan.blogspot.in/ I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful !!!

    Monday, January 21, 2013 5:42 AM
  • Hello,

    Everything what Chandan wrote is correct except one line:

    instead of

    IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

    should be used

    IOrganizationService service = serviceFactory.CreateOrganizationService(null);


    Freelance Developer for Dynamics CRM 4.0/2011

    Monday, January 28, 2013 9:54 AM
    Moderator
  • Hello Andrii,

    What's the reason behind having null instead ?? I search eveywhere but I found  context.UserId is the right value!!!


    hussain

    Saturday, February 2, 2013 9:43 PM
  • Null should be used because in case null is passed - Endpoint is created with top privileges (you are authenticated from the same of System account).

    So my code implements the same code as you've asked for 4.0.


    Freelance Developer for Dynamics CRM 4.0/2011

    Sunday, February 3, 2013 8:23 AM
    Moderator