Problem with macro running from rule

T

Teki

I use outlook 2003 with exchange server. When I receive mail from specific
email address I want to move it to specific folder based on string in subject
and than pare the subject of mail and create new user property with value
parsed from subject.
Now I have macro that is capable of parsing the subject and adding parsed
value to new user property and outlook rule that moves mail based on address
and subject.

Problem is that macro works fine and rule works fine, but together they
don't work correct.
It seems that when mail is received macro creates user property correctly,
but than mail is moved and the value in user property is lost (maybe because
of connection with exchange?). If I create separate rules - one that executes
macro and other that moves mail they work fine if I execute each one
individually (by hand). If they are executed automaticaly, when mail is
received user property is gone. (I've tried different combinations.. e.g.
rule 1 than rule 2, rule 2 than rule 1). It just wont work.

Any help would be appreciated.

Here is my macro code:
Sub Jira(MyMail As Outlook.MailItem)
Dim strID As String
Dim Item As Outlook.MailItem
Dim olNS As Outlook.NameSpace

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set Item = olNS.GetItemFromID(strID)

mailSubject = Item.Subject

posStart = InStr(mailSubject, "(")

posEnd = InStr(mailSubject, ")")

jiraIDLen = posEnd - posStart

jiraId = Mid(mailSubject, posStart + 1, jiraIDLen - 1)

Dim prop As Outlook.UserProperty

Set prop = Item.UserProperties.Find("JiraID")

If TypeName(prop) = "Nothing" Then
Set prop = Item.UserProperties.Add("JiraID", olText, True)
prop.Value = jiraId

Item.Save
End If

End Sub

Thnx.
 
K

Ken Slovak - [MVP - Outlook]

Why are you instantiating Item when you're being passed a perfectly good
MyMail object? Try working only on MyMail and see what happens. I'd also
have the macro code do the moving and remove that from the rule.
 
S

Sue Mosher [MVP-Outlook]

Why are you instantiating Item when you're being passed a perfectly good
MyMail object?

I recognize this as probably derived from some of my code. MyMail is not
trusted by the "object model guard." Therefore, Item is instantiated using
GetItemFromID and MyMail.EntryID, so that Item *is* a trusted object. That's
not terribly relevant for this particular scenario, which doesn't use any
blocked properties or methods, but it's definitely a general model for a "run
a script" rule.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
S

Sue Mosher [MVP-Outlook]

What symptoms suggest that "the value in user property is lost" when the item
is moved? Where is it being moved to?
 

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