How to check a new item against a filtered view to see if it matches?

J

John Riddle

Hello,

I have some custom code that allows a user to save a view (such as when they
run a filter against items in a public folder). Now the users want a
notification when a new item is added to the folder that fits one of their
custom filters. I can easily create a newitem event for the folder and then
check the custom views whenever an item is added to get the various filters
that might be applied. The resulting filtered part of the XML would look like
this:

<filter>(&quot;urn:schemas:httpmail:textdescription&quot; LIKE '%oracle%' AND
&quot;urn:schemas:httpmail:textdescription&quot; LIKE '%java%' AND
&quot;urn:schemas:httpmail:textdescription&quot; LIKE '%unix%')</filter>

Now, I don't want to run each saved filter against the folder and check to see
if any of the resulting items match the item just added. That would hang the
user's computer for too long each and every time an item was added to the
public folder. What I would like to do is simply check this filter against the
one (1) new item itself.

Can somebody tell me if there's an easy way to see if the new item's (contact
item) properties match those specified in the custom filter?

Thanks,

John
 
K

Ken Slovak - [MVP - Outlook]

If I understand what you want you can set up an Items collection handler
class for each folder of interest and store those classes in a collection to
keep the references alive. Then you can handle the ItemAdd event, which
passes you the Item that was added. It's like using Explorer and Inspector
wrappers.
 
G

Guest

I can think of a few ways to handle this, but I'm not sure which is the best
approach:

- you can use the AdvancedSearch method to return a result set using the
current filter, and loop through it to see if the new message is in there; it
*shouldn't* consume too much time, but test and see
- what about tracking the last message counts for the particular view (or
all of them), and when the new item comes in, see if the message count for
the folder with the view applied has incremented by one - if it has, then the
message satisfied that criteria
- otherwise you'd have to extract the DASL properties from the filter, and
map it to the relevant Outlook Object Model property. This would probabaly
involve reading the mapped values from a file though, unless you laboriously
coded the mappings. You can see the mappings on OutlookCode.com at
http://www.outlookcode.com/files/schema.zip
 
J

John Riddle

Eric,

Thanks. That gave me some really good ideas. How do I get the Message Count
for a VIEW? I know how to do this for an Items Collection, but that doesn't
help me to know if the new item is also part of the filtered results.

I've looked at the properties for the View object and there doesn't seem to be
a "count" property. I could of coarse, apply the filter and get the items
count, but that general takes 2-10 seconds depending upon the complexity of
the filter. I can't lockup everyone's computer for 2-10 seconds every time
anyone else in the office saves a contact. People would be constantly
interupted from what they were doing in Outlook just to check if by chance the
new contact saved by someone else matches a very specific search that they had
saved.

I have over 150 custom properties in my custom contact form so I'd have to add
these to the list to use option 3. Actually, option 3 was what I thought I'd
have to do originally, but was hoping for an easier solution if available as
I'm not sure if that would hange outlook as well each time the code processed.

Thanks,

John


message I can think of a few ways to handle this, but I'm not sure which is the best
approach:

- you can use the AdvancedSearch method to return a result set using the
current filter, and loop through it to see if the new message is in there; it
*shouldn't* consume too much time, but test and see
- what about tracking the last message counts for the particular view (or
all of them), and when the new item comes in, see if the message count for
the folder with the view applied has incremented by one - if it has, then the
message satisfied that criteria
- otherwise you'd have to extract the DASL properties from the filter, and
map it to the relevant Outlook Object Model property. This would probabaly
involve reading the mapped values from a file though, unless you laboriously
coded the mappings. You can see the mappings on OutlookCode.com at
http://www.outlookcode.com/files/schema.zip
 
J

John Riddle

Ken,

Thanks for your attention to this. Yes, I've already created the items
collection and am using the Item_Add event of that collection to get the new
item. The question was about how to take that item and easily match it to a
saved view (specifically, the filtered part of the view(s) saved in the user's
profile) to see if there was a match without interupting the users' activities
or spending more time on the code than it's worth. (I have 10 users and I
don't get paid for the programming, so I don't want to spend more of my time
than it's worth. If there's a fairly easy method, then great, I'll do it).

I can extract the XML of the view and see the filtered code such as:

<filter>(&quot;urn:schemas:httpmail:textdescription&quot; LIKE '%oracle%'
AND
&quot;urn:schemas:httpmail:textdescription&quot; LIKE '%java%' AND
&quot;urn:schemas:httpmail:textdescription&quot; LIKE '%unix%')</filter>

This however, is an example of a "simple" filter. Other filters have multiple
levels of AND/OR's and filter on many different custom properties.

Thanks,

John


If I understand what you want you can set up an Items collection handler
class for each folder of interest and store those classes in a collection to
keep the references alive. Then you can handle the ItemAdd event, which
passes you the Item that was added. It's like using Explorer and Inspector
wrappers.
 
G

Guest

Yeah, you'd have to set the View to apply the filter, and then access the
Items.Count property, so you are still faced with a delay.

A better option is to implement this logic in an Exchange Event Sink
published to that folder. Then all the processing will be server side, and
the sink can also send notification messages when the criteria is satisfied.
 
J

John Riddle

Yeah, I tried it the other way and it is VERY slow. Can use that for the
users.

I've never written an Exchange Event Sink. Is there a sample one available
that I could modify with my own processing code?

Thanks,

John


message Yeah, you'd have to set the View to apply the filter, and then access the
Items.Count property, so you are still faced with a delay.

A better option is to implement this logic in an Exchange Event Sink
published to that folder. Then all the processing will be server side, and
the sink can also send notification messages when the criteria is satisfied.
 
K

Ken Slovak - [MVP - Outlook]

You'd have to write code to analyze each view then, converting the XML and
the DASL syntax for the property tags into something you can use in your
code. Nothing easy I'm afraid.
 
G

Guest

There is a sample VB6 project in the Exchange SDK Tools download:

Download details: Exchange SDK Development Tools:
http://www.microsoft.com/downloads/...4-C209-4A73-AC5D-FF2A4A3B48B7&displaylang=en

Also grab the full SDK (links at the bottom of above). For newsgroup
support, see microsoft.public.exchange.development.

Events sinks can be daunting at first, but once you master the basics you
have a lot of power at your hands, far beyond what VBA/VB event hooks with
the Outlook Object Model, the Rules Wizard or the Folder Assistant can offer.
 
J

John Riddle

Yep, that's what I suspected. Didn't know if there was a way to treat the item
passed as a collection of 1 item and apply the filter to it somehow. Perhaps I
could copy the items to a temp folder, apply the views to those folders every
hour or so with just a few items in the folder and if a match is made find the
real item in the Public Folder and send a link to it to the user. Pretty messy
work around.

John

You'd have to write code to analyze each view then, converting the XML and
the DASL syntax for the property tags into something you can use in your
code. Nothing easy I'm afraid.
 

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