locked
Enable user programmatically CRM 2011 RRS feed

  • Question

  • Hi Everyone,

    I am trying to disable a user programmatically in a plug-in. I am using the following code snippet:

    SetStateRequest setStateReq = new SetStateRequest();
    setStateReq.EntityMoniker = new EntityReference("systemuser", userId);
    setStateReq.State = new OptionSetValue(0);
    setStateReq.Status = new OptionSetValue(-1);
    
    SetStateResponse response = (SetStateResponse)service.Execute(setStateReq);

    The userId holds the Guid of the user needed to disable, service is an IOrganizationService.

    The code runs without error, but the user does not get disabled. Any ideas what is possibly going wrong?

    I don't know if it has anything to do with it, but I'm using CRM online.

    Wednesday, April 10, 2013 2:29 PM

Answers

  • Try:

    SetStateRequest setStateReq = new SetStateRequest();
    setStateReq.EntityMoniker = new EntityReference("systemuser", userId);
    setStateReq.State = new OptionSetValue(-1);
    setStateReq.Status = new OptionSetValue(-1);
    
    SetStateResponse response = (SetStateResponse)service.Execute(setStateReq);


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Wednesday, April 10, 2013 2:35 PM
    Moderator

All replies

  • Try:

    SetStateRequest setStateReq = new SetStateRequest();
    setStateReq.EntityMoniker = new EntityReference("systemuser", userId);
    setStateReq.State = new OptionSetValue(-1);
    setStateReq.Status = new OptionSetValue(-1);
    
    SetStateResponse response = (SetStateResponse)service.Execute(setStateReq);


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Wednesday, April 10, 2013 2:35 PM
    Moderator
  • Thank you, that one did work.
    Wednesday, April 10, 2013 2:56 PM