Question

I am attempting to change the "FullName" field of existing CRM system users in our Dynamics CRM 2011 Online account. I have already made the change in settings to update all future users to the format "Last, First" ... so this is for changing the existing users.

I read the best way is to do this programmatically using the CRM SDK. When I perform the actual Update command, I receive an unspecified error from the SDK: Additional information: The property IsLicensed cannot be modified.

Although I'm querying all columns for entity object SystemUsers, I'm only changing the FullName field. Has anyone else had experience with this? My code is below, I'm running this as a console app to step through each SystemUser.


    static void Main(string[] args)
    {
        string connStr = ConfigurationManager.ConnectionStrings["CRMOnline"].ToString();
        CrmConnection conn = CrmConnection.Parse(connStr);
        conn.DeviceCredentials = DeviceIdManager.LoadOrRegisterDevice();
        using (OrganizationService svc = new OrganizationService(conn))
        {
            QueryExpression qry = new QueryExpression();
            qry.ColumnSet = new ColumnSet(true);   // get all columns
            qry.EntityName = CRMO.SystemUser.EntityLogicalName;   // get entity object SystemUser
            qry.Criteria.AddCondition(new ConditionExpression("calendarid", ConditionOperator.NotNull));   // but non-builtin users
            EntityCollection col = svc.RetrieveMultiple(qry);  // executes query

            foreach (Entity ent in col.Entities)
            { 
                Console.WriteLine();
                Console.WriteLine("Current Fullname: " + ent.Attributes["fullname"].ToString()); 
                Console.Write("Change? y/N: ");
                string ans = Console.ReadLine();
                if (ans.ToLower() == "y")
                {
                    Console.Write("New Name: ");
                    string newname = Console.ReadLine();
                    if (newname != "")
                    { 
                        ent.Attributes["fullname"] = newname;
                        svc.Update(ent);  // fails here with SDK error:  "Additional information: The property IsLicensed cannot be modified." 
                    } 
                }  
            }
            Console.WriteLine();
            Console.WriteLine("--- Done ---");
            Console.ReadLine(); 
        }  
    }
Was it helpful?

Solution 2

This is so others reading this can use this solution to change the FullName in CRM Online.

So in my case, where I needed to change the FullName of existing CRM users from "First Last" to "Last, First", I was able to perform regular Office 365 admin functions to complete this.

First, I changed the format in CRM Settings > System Settings to "Last Name, First Name".

Then, for each user I needed to have changed, I used the Office 365 Admin Center and edited their licenses. Un-assign the CRM license from the user and click SAVE. Wait about a minute or two for the changes to take affect. Next, go back into that same user management and re-assign the CRM license to the user, click SAVE. Wait a few minutes and you will see the FullName in CRM should be in the correct format.

OTHER TIPS

Rule 28 of the Crm SDK, don't ever perform updates by performing a select, which returns back more fields than what you are planning to update. Any fields in the attribute collection of the Entity will be updated even if they haven't changed. Instead, instantiate a new entity locally, set the id and whatever attributes you want to update and update it.

On a side note, you can't update the full name of a System User. You have to update the individual pieces. So your code should really look like this:

static void Main(string[] args)
{
    string connStr = ConfigurationManager.ConnectionStrings["CRMOnline"];
    CrmConnection conn = CrmConnection.Parse(connStr);
    conn.DeviceCredentials = DeviceIdManager.LoadOrRegisterDevice();
    using (OrganizationService svc = new OrganizationService(conn))
    {
        QueryExpression qry = new QueryExpression();
        qry.ColumnSet = new ColumnSet("firstname", "lastname", "fullname");   // get only what is needed for performance reasons
        qry.EntityName = CRMO.SystemUser.EntityLogicalName;   // get entity object SystemUser
        qry.Criteria.AddCondition(new ConditionExpression("calendarid", ConditionOperator.NotNull));   // but non-builtin users
        EntityCollection col = svc.RetrieveMultiple(qry);  // executes query

        foreach (Entity ent in col.Entities)
        { 
            Console.WriteLine();
            Console.WriteLine("Current Fullname: " + ent["fullname"].ToString()); 
            Console.Write("Update? Y/N: ");
            string ans = Console.ReadLine();
            if (ans.ToLower() == "y")
            {
                // Create a new entity, setting the id and whatever attributes that need to be updated
                var updateEntity = new Entity { Id = ent.Id };
                updateEntity["firstname"] = ent["firstname"];
                updateEntity["lastname"] = ent["lastname"];
                svc.Update(updateEntity);
            }  
        }
        Console.WriteLine();
        Console.WriteLine("--- Done ---");
        Console.ReadLine(); 
    }  
}

Notes:

  • Only retrieve the columns you actually need
  • Create an update entity that only contains the fields you want to update
  • Remember that FullName is readonly

This may also be helpful

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top