Messed up Smart Object keys causing 'key does not exist' exception

  • 20 February 2008
  • 3 replies
  • 0 views

Badge +5
I'm uisng a Smart Object to get a list of items from a SharePoint list. To set up the smart object I deleted all the methods, added a GetList method, linked it to the SharePoint list, and then 'auto-created' the smart object properties. This works fine.

Here's the problem. One of the properties is called (for example) “Manager Name”. I should be able to use the following:

So.Properties[“Manager Name”].Value.ToString()

But this throws a ‘Key does not exist in the collection’ exception. However, if I type

So.Properties[0].Value.ToString()

It works perfectly. I stepped in with the debugger and found out that if I type

So.Properties[“Title”].Value.ToString()

I get the value for the Manager Name! The other properties also have messed up keys. If I look at the smart object in VS I see 'Manager Name' and NOT 'Title'. None of the properties are SmartBox properties.

I've now had to resort to using integers to access the properties of my Smart Object which is now inconsistent for the rest of my smart objects, all of which work perfectly with keys.

Anyone else seen this? Any workarounds? I'm using SP1.

Thanks in advance!

3 replies

Badge +3

It sounds to me like you renamed columns in your SharePoint list. So for example, that list probably had a "Title" column that you renamed to "Manager Name". Programatically, SharePoint still thinks of it as "Title". Therefore, the SmartObject needs to refer to it as "Title" in order to get SharePoint to give up the value. I know this was an issue with accessing columns programatically in SharePoint 2003, it doesn't surprise me if the issue is still in SharePoint 2007.


 

Badge +5
icon-quote.gifcodik:

It sounds to me like you renamed columns in your SharePoint list. So for example, that list probably had a "Title" column that you renamed to "Manager Name". Programatically, SharePoint still thinks of it as "Title". Therefore, the SmartObject needs to refer to it as "Title" in order to get SharePoint to give up the value. I know this was an issue with accessing columns programatically in SharePoint 2003, it doesn't surprise me if the issue is still in SharePoint 2007.



That's a very good point Codik, and you are correct, although I still don't think I can shift all the blame to SharePoint for this one. At the point of using my code I am using smart objects only - the fact that the smart object is getting populated from a sharepoint list should be transparent at this point.

The fact that i can't use the smart object property names as keys still points to a blackpearl problem imho. The smart object can use 'Title' instead of 'Manager Name' when polling the SharePoint list if it wants to, but I would expect to be able to use the name I see in the property list.

Thanks though!
Badge +1

This is caused by the order of your fields in the smartobject definition. It happens if you add fields /  columns to your database table and refresh the service instance.


Unfortunately just using the 'move up' and 'move down' does not seem to work in the version of blackpearl I am using, as it does not save the order. When the kprx is closed down and opened up agin the order is still wrong.


 To get around this close down the kprx. Open the sodx file in an xml editor and manually move the <SmartPropertyDefinition /> nodes into alphabetical order.

Reply