Monday, August 28, 2006

MOSS 2007 Beta2 bug - Profile Database Property's Choicelist Cannot Be Updated By Code

I spent a long time trying to figure out what I was doing wrong before giving up and reporting this, just to get a reply that MS knows about the problem and are working on a fix!!!
And here I was using reflector trying to see how MS did that in their controls.

The problem is when you are using the portal object model to change a property in the profiles database.
For example, I was trying to add, update or remove values from a choice list in a property. I had a property called "Location", and I wanted to create an automated application that will update the choices the user can choose from.

After a quick search in the SDK, I wrote the code I needed to run:

using (SPSite site = new SPSite("http://servername"))
            {
                   ServerContext context = 
                       ServerContext.GetContext(site);
                   UserProfileManager m_mngr = new UserProfileManager(context);

                   //Get the properties
                   PropertyCollection props = m_mngr.Properties;
                   Property location = props["Location"];
                   property.ChoiceList.Add("Sydney");
                   property.Commit();
               }
            }

If I ran it in a web application (web part) or a console application, and then immediately requery the choice list, it appears to work, but then if you clear the application cache, or if you just go to the administration page for the property you can see the values were not updated.

The real depressing bit is that I really need this to work, since my project needs to go live in a month, and if Microsoft doesn't fix that in the Beta 2 Refresh, I don't know what I will do!

2 comments:

Anonymous said...

I know exactly what your feeling.

My situation has to do with profile properties as well regarding vanilla LDAP imports

http://www.sharepointblogs.com/aspire

From those I have spoken with, I am not sure MOSS is really ready for RTM...

Anonymous said...

I had this same problem with the RTM version.


The workaround is to set something else on the Property which seems to 'trigger' that it needs to be saved. For example:


skillsprop.ChoiceList.Add("Hello");
skillsprop.Description = "";
skillsprop.Commit();