ChangeState Operation for User (SystemUser) entity in Dynamic CRM 2013 RRS feed

  • Question

  • Hi All,

    Currently I am working on "user" (systemuser) entity.

    In this entity, I want to perform change state operation means I want to activate or deactivate specific user depending on their unique Guid.

    I tried ChangeState Operation using "SetStateRequest"  but I got error as "Error 1250: Dynamics CRM call error: Could not find an attribute with specified name: statecode".

    Does "user"(systemuser) entity has "Statecode" attribute in it's propertybag ? If yes, How to perform change state operation for "user" entity ? Does it requires any special request to perform this operation?

    Please suggest.



    Tuesday, October 14, 2014 9:33 AM


All replies

  • Hi Sud,

    see if this helps?




    Tuesday, October 14, 2014 10:05 AM
  • Hi Jithesh,

    Thanks for reply.

    Please have a look at the code - 

      Creating Change State request as - 

                                            changeState = new SetStateRequest();
                                            changeState.EntityMoniker = new EntityReference();
                                            changeState.EntityMoniker.Id = entities.Entities[i].Id; // setting guid
                                            changeState.EntityMoniker.LogicalName = entities.Entities[i].LogicalName; // setting logical name

                                            if (!string.IsNullOrWhiteSpace(status))
                                                changeState.Status = new OptionSetValue(Convert.ToInt32(status)); // read from code i.e "1"
                                            if (!string.IsNullOrWhiteSpace(state))
                                                changeState.State = new OptionSetValue(GetStateCode(entity.LogicalName, state));  // state is "Inactive"


     public int GetStateCode(string entityName, string state)
                RetrieveAttributeRequest attribReq = new RetrieveAttributeRequest();
                attribReq.EntityLogicalName = entityName;
                attribReq.LogicalName = "statecode";
                attribReq.RetrieveAsIfPublished = true;

                RetrieveAttributeResponse amRes = (RetrieveAttributeResponse)serviceProxy.Execute(attribReq);
                AttributeMetadata attributeMetadata = amRes.AttributeMetadata;
                StateAttributeMetadata stateAttrib = (StateAttributeMetadata)attributeMetadata;

                OptionMetadata opMetaData = stateAttrib.OptionSet.Options.ToList().Find(op => op.Label.UserLocalizedLabel.Label.ToLower() ==     state.ToLower());
                return opMetaData.Value.Value;


    In the function GetStateCode(), it throws execption at the statement - 

     RetrieveAttributeResponse amRes = (RetrieveAttributeResponse)serviceProxy.Execute(attribReq);

    as shown in image.

    My doubts is, Does "user"(systemuser) entity has "Statecode" attribute in it's propertybag ? If yes, How to perform change state operation for "user" entity ? 

    Tuesday, October 14, 2014 12:58 PM
  • Hi Sud,

     I am not sure what type is serviceProxy? are you getting the value similar to this sample?.




    • Marked as answer by Sud Gujar Monday, October 27, 2014 10:35 AM
    Tuesday, October 14, 2014 1:14 PM