Empty UserProperties and PropertyAccessor

J

Jeff

Hi All

I've got the following strange problem. Language == C++

I've added custom properties to the containg outlook contact folder and
create the contact item using replacement form regions. Within
the form regions all the custom values are saved and redisplayed every time
you open and close the contact item.

BUT, if I grab the items collection for the folder and access each contact
item, the UserProperties items are "empty". ie: have no value and
a the count for the collection is 0

ie:
_ItemsPtr spItems = NULL;
MAPIFolderPtr spFdr = GetListingsFolder(m_spApp);
if(spFdr){
spItems = spFdr->Items;
}


if(spItems){
_ContactItemPtr spContact;
for(int i=1; i<=spItems->Count; i++){
spContact = spItems->Item(i);

UserPropertiesPtr spProps = spContact->UserProperties;
int ic = spProps->Count;

ie:
UserPropertyPtr spProp = spContact->UserProperties->Item("RE MY Value");
if(spProp ==NULL){
Barf.... Allways...
}

Strangly, I can access most of the custom properties using the
PropertyAccessor:

ie:
PropertyAccessor->GetProperty(http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/RE%20MY%20Value);

But NOT if the custom property is a Currancy value. In the case of currancy
values, I can access them if I have just resaved them using the form region,
but not if Outlook
has been shut down and restarted. :S

It seems to me, that the UserProperties are not being loaded when the items
collection is filled. Is there any way to "Force" the loading of the
UserProperties for each item in the items collection?

Any ideas? Thanks!
 
J

Jeff

Interestingly, using Outlook Spy, it does not see the UserProperties either
on the contact item, when it is in the folder ( selected ) but DOES
when the item is open in the Form Region ( Outllook 2007 )

Looking at the item useing Outlook Spy's IMessage view, all the properties
are there.

Very Odd...

Any Ideas?
 
J

Jeff

Alright.... Using Dmitry Streblechenko's excellent Outlook Spy product I
discovered what the problem was / is.

I modified one of the Contact's using OL's All Properties page and what ya
know... the UserProperties were all saved and accessible via the Item?

So I used Outlook Spy to compare this Contact to one that didn't have the
UserProperties.

The Contact showing the problem was missing the IMAP "UserProperties"
PT_BINARY tag. So, even though all the UserProperties
themselves were stored in the IMAP IMessage Properties, since this
particular tag was missing, accessing the item via the Outlook objects did
not
return the UserProperties collection. I assume the IMAP "UserProperties" tag
is some kind of internal tab used by OL.

It seems ( at least via Native C++ ) if you have a custom Form Region
connected to ContactItem, OL will NOT save the UserProperties collection.
But, you can force it to by adding a "UserProperty" programmatically and
then saving the item ( the workaround ). Oddly, OL WILL save Form Region
generated UserProperties as IMAP Properties in the
{00020329-0000-0000-C000-000000000046} namespace.

I hope my explanation is a little clearer than mud and this helps someone
else.

Personally, I think this behaviour is an Outlook 2007 Form Region related
bug.

Thanks Dmitry!
 
J

Jeff

Well... it get's weireder.... It appears to happen only with the FormRegions
I am making, using OL's form designer.

If I use a FormRegion from sample code, it all works fine. But if I create a
new FormRegion using Tools->Forms->Design a Form
the new form will not save the UserProperties :S

VERY STRANGE!

Any ideas anyone?
 
K

Ken Slovak - [MVP - Outlook]

How are you trying to save the user properties? Are you binding the fields
on the form region to already existing user properties or one created when
you bind the fields?
 
J

Jeff

Hello Ken

I use the "New" button to create a new field, from the control's Properties
Value page.

Thanks

Jeff
 
J

Jeff

Just now... once again... ;)

Seperate Region

The only thing I see from the walk-through different than I, is they use the
fields dialog to add the new field
and I used the properties page.

From the known issues:

"The UserProperties collection may not be valid in the GetFormRegionStorage
event" shouldn't be an issue, since I'm looking at them during
the BeforeFormRegionShow and besides, they are there, once I "work around"
the problem.

The "Custom fields may not persist on separate form regions" might be a part
cause of the issue I suppose, but I don't see how. I add the new values on
the custom form region and then save the item, yet the values do not
persist. So I think not.

I'm lost... :(
 
K

Ken Slovak - [MVP - Outlook]

See if using the fields dialog to add the user properties makes a
difference. To be honest that's how I do it and I haven't had problems (I
don't use the Properties page usually to add user properties). I'm wondering
if the user properties added the way you're doing it might not be adding the
fields to the folder and just to the items.
 
B

Bob Martin

I have encountered the same problem identified by Jeff. I am using Visual
Basic to interact with a FormRegion on a Contact form. I created four
UserProperty fields in the FormRegion by dragging them from the Field
Chooser, with the filter set to "UserProperties in this folder" (so I know
the problem is not due to the UserProperties not having been added to the
Contact folder). I have written a dialog which, based on user input to the
dialog, in code sets the UserProperties in the FormRegion. I have tried
setting each UserProperty directly:

Dim oProp As Outlook.UserProperty
Set oProp = ContactItem.UserProperties.Find("Group")
oProp.Value = strGroup

and also tried setting each UserProperty by manipulating the text box in the
FormRegion that displays the UserProperty:

olkGroup.Value = strGroup

Either way, the UserProperties are saved in the ContactItem and are
redisplayed when I reopen the Contact form. However, when I access the
ContactItem in code (i.e., without opening the Contact form), the
UserProperties.Count is 0 and UserProperties.Find cannot find any
UserProperties.

Jeff's workaround solves the problem. Before setting the UserProperties in
the FormRegion in an open Contact form, I do the following:

oItem.UserProperties.Add "Bogus", olText
oItem.UserProperties.Find("Bogus").Delete

After I do that, when I access the ContactItem in code, the ContactItem
returns the correct UserProperties.Count, and UserProperties.Find retrieves
the UserProperties.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top