Assign Categories "Round Robin" style but in a shared mailbox but on specific emails only

reubendayal

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Exchange Server 2013
Hi All,

I am trying to auto assign categories to incoming emails. But these need to be applied on emails that match a certain criteria only for e.g. the sender's email address and a specific phrase in the subject line and the category applied to the email from the exchange server.

I need to assign these categories to those specific emails only, and these emails concern a specific case, but there are normally two emails that come per case and they usually arrive back to back. the categories I want to apply is basically to assign a team member's category color and this should follow a "round robin" or sequence style. So one case to team member "John" and the next 2 emails of the case to "Jane" and then back to john again and so on. Just so the workload is shared equally. The other problem is that the shared mailbox is used for general casework so there is a lot of emails that come to the mailbox. So I have now made a rule on the exchange server to assign a category "NewCase" to every new case email and also, to make a copy of it in a separate folder to keep track of whom the latest case was assigned to.

From the code on assigning categories "round robin" style from this page Use a Macro to Assign Messages in a Shared Mailbox I tried applying the VBA code in ThisOutlookSession using the GetFolderPath function, but that function has for some reason never worked for me. So I have now created a rule on my outlook client to run a script on incoming messages. And am trying to trigger the assigning of categories for the team from that script.

I have run in to several problems with the tweaked code I have so will not mess with that anyfurther, and would rather seek help.

At the moment I am able to get from the subfolder with the copy of the incoming case emails the category of whom the latest case was assigned. So to know whom should the new case emails in the inbox be assigned to. But I am quite clueless about where to go from there.

Please help!

Reuben
 

reubendayal

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Exchange Server 2013
Hi All,

I am trying to auto assign categories to incoming emails. But these need to be applied on emails that match a certain criteria only for e.g. the sender's email address and a specific phrase in the subject line and the category applied to the email from the exchange server.

I need to assign these categories to those specific emails only, and these emails concern a specific case, but there are normally two emails that come per case and they usually arrive back to back. the categories I want to apply is basically to assign a team member's category color and this should follow a "round robin" or sequence style. So one case to team member "John" and the next 2 emails of the case to "Jane" and then back to john again and so on. Just so the workload is shared equally. The other problem is that the shared mailbox is used for general casework so there is a lot of emails that come to the mailbox. So I have now made a rule on the exchange server to assign a category "NewCase" to every new case email and also, to make a copy of it in a separate folder to keep track of whom the latest case was assigned to.

From the code on assigning categories "round robin" style from this page Use a Macro to Assign Messages in a Shared Mailbox I tried applying the VBA code in ThisOutlookSession using the GetFolderPath function, but that function has for some reason never worked for me. So I have now created a rule on my outlook client to run a script on incoming messages. And am trying to trigger the assigning of categories for the team from that script.

I have run in to several problems with the tweaked code I have so will not mess with that anyfurther, and would rather seek help.

At the moment I am able to get from the subfolder with the copy of the incoming case emails the category of whom the latest case was assigned. So to know whom should the new case emails in the inbox be assigned to. But I am quite clueless about where to go from there.

Please help!

Reuben
Hi All,

Further to the above, here's the code/script, I trigger using the rules in outlook. So as per the rule if the sender's email address, the specific subject text and the category colour already assigned from the exchange server start this script.

Code:
Public Sub ShowMessage(Item As Outlook.MailItem)

    Dim strCat As String
    Dim Sender As Outlook.AddressEntry
    Set Sender = Item.Sender

    Dim strMailboxName As String
    Dim MyFolder As Folder
    Dim myItems As Items
    Dim mItem As MailItem
    Dim e As Long
    Dim i As Integer
    
    
    strMailboxName = "SharedClients"
    Set MyFolder = Session.Folders(strMailboxName)
    Set MyFolder = MyFolder.Folders("Inbox").Parent.Folders("Copy of Initiations From Team")

    Set myItems = MyFolder.Items
    myItems.Sort "ReceivedTime", True

    If myItems.Count > 0 Then
        Set mItem = myItems.Item(1)
        
        
        MsgBox MyFolder.FolderPath
        
        If mItem.Categories = "John; NewCase" Then
'        MsgBox "John Category"
            i = 2 'Call JaneShowMessage
        ElseIf mItem.Categories = "Jane St. Claire; NewCase" Then
'        MsgBox "Jane Category"
            i = 0 'Call JohnShowMessage
        Else
        MsgBox "Didnt work"
        End If
    
    End If

    If Item.Class = OlMail Then 'And Item.Categories = "NewCase" And Item.Sender = CE Global Maersk Immigration <maerskimmigration@deloittece.com> And Not Item.Categories = "John" Or Not Item.Categories = "Jane"
'    MsgBox "i count = " & i

'MsgBox "i value: " & i

    Select Case i
     Case 0
          strCat = "John"
     Case 1
          strCat = "John"
     Case 2
          strCat = "Jane"
     Case 3
          strCat = "Jane"
        
    End Select
    Item.Categories = Item.Categories & ";" & strCat
        Item.Save
    Err.Clear
     End If
     i = i + 1
     Debug.Print i
     MsgBox i
     If i = 4 Then i = 0

End Sub
The code calculates i = 2, as I have assigned John and NewCase on the latest email in the case initiations copy folder. But the case select bit of it, makes i = 3 and the code simply assigns the case emails in the inbox to "Jane" category. I do not know whether a for loop will solve the problem. Also, I am quite a novice with For loops, so cant put that code together.

Anyone that can help with this?

Thanks again.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
code in ThisOutlookSession using the GetFolderPath function,
You only need the function if the mailbox is not your default data file. If you are using a shared exchange mailbox, you'd use different code.


With a rule, you need to have all actions in the script - add the category, copy the message.

I'm not sure what the sort and if statements is doing - when you use a rule, it applies to the message that triggers the rule. you don't need to find the messages.
Code:
    Set myItems = MyFolder.Items
    myItems.Sort "ReceivedTime", True
    If myItems.Count > 0 Then
        Set mItem = myItems.Item(1)

        MsgBox MyFolder.FolderPath

        If mItem.Categories = "John; NewCase" Then
'        MsgBox "John Category"
            i = 2 'Call JaneShowMessage
        ElseIf mItem.Categories = "Jane St. Claire; NewCase" Then
'        MsgBox "Jane Category"
            i = 0 'Call JohnShowMessage
        Else
        MsgBox "Didnt work"
        End If
    End If


Code:
Private Sub SetCatergoiesCopy(ByVal Item As Object)
    Dim strCat As String
    
    If Item.Class = olMail Then
    
    Select Case i
     Case 0
          strCat = "John"
     Case 1
          strCat = "John"
     Case 2
          strCat = "Jane"
     Case 3
          strCat = "Jane"
    End Select
        
    Item.categories = strCat
            Item.Save
        Err.Clear
     End If
     i = i + 1
     Debug.Print i
     If i = 4 Then i = 0

'now move a copy
strMailboxName = "SharedClients"
    Set MyFolder = Session.Folders(strMailboxName)
    Set MyFolder = MyFolder.Folders("Inbox").Parent.Folders("Copy of Initiations From Team")

itemCopy = item.copy
itemcopy.move myfolder
 End Sub
 

reubendayal

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Exchange Server 2013
You only need the function if the mailbox is not your default data file. If you are using a shared exchange mailbox, you'd use different code.


With a rule, you need to have all actions in the script - add the category, copy the message.

I'm not sure what the sort and if statements is doing - when you use a rule, it applies to the message that triggers the rule. you don't need to find the messages.
Code:
    Set myItems = MyFolder.Items
    myItems.Sort "ReceivedTime", True
    If myItems.Count > 0 Then
        Set mItem = myItems.Item(1)

        MsgBox MyFolder.FolderPath

        If mItem.Categories = "John; NewCase" Then
'        MsgBox "John Category"
            i = 2 'Call JaneShowMessage
        ElseIf mItem.Categories = "Jane St. Claire; NewCase" Then
'        MsgBox "Jane Category"
            i = 0 'Call JohnShowMessage
        Else
        MsgBox "Didnt work"
        End If
    End If


Code:
Private Sub SetCatergoiesCopy(ByVal Item As Object)
    Dim strCat As String
   
    If Item.Class = olMail Then
   
    Select Case i
     Case 0
          strCat = "John"
     Case 1
          strCat = "John"
     Case 2
          strCat = "Jane"
     Case 3
          strCat = "Jane"
    End Select
       
    Item.categories = strCat
            Item.Save
        Err.Clear
     End If
     i = i + 1
     Debug.Print i
     If i = 4 Then i = 0

'now move a copy
strMailboxName = "SharedClients"
    Set MyFolder = Session.Folders(strMailboxName)
    Set MyFolder = MyFolder.Folders("Inbox").Parent.Folders("Copy of Initiations From Team")

itemCopy = item.copy
itemcopy.move myfolder
End Sub
Hi Diane,

Thank you for your reply.

I am sorry I wasn't clear in explaining the code and my plan with it.

It is correct that I am trying to make this script work on the shared mailbox as it is our team's common mailbox. So for proactively coloring the new case initiation emails, I have setup a rule on the OWA of the shared mailbox. So already when the email arrives from the server in to our outlook clients, the email comes with the NewCase color category. Also what I do is from another rule on the OWA I make a copy of the initiation emails to the "Copy of Initiations From Team" folder under the share mailbox's inbox.

Then once the initiation emails arrive in the shared mailbox, I am using the received time and IF statements at the beginning of the script to check from the "Copy of Initiations From Team" folder, by sorting it by date, and then taking the latest email (the first one from the of the list), and see who the last case was assigned to (John or jane). Thus giving "i" a value of 0 or 2. To then use thaa value and assign the correct category color on the subsequent new case initiations emails that come in. I couldn't think of another way of keeping track of whom the last case email was assigned to. Please feel free to suggest if this can be done in another way.

In the rule on the outlook client, I am only using the senders email, the subject line text and the "NewCase" category (already assigned from the OWA/server), to trigger the rule. And the only action I have in rule is to "Run a script". And then the rest is done via the script VBA.

I hope I have explained the issue better now.

p.s.: I have tried the steps on the Working with VBA and non-default Outlook Folders, but that too has not worked well for me. So a while someone had showed me this way of assigning the shared mailbox, and doing whatever with it:


strMailboxName = "SharedClients"
Set MyFolder = Session.Folders(strMailboxName)
Set MyFolder = MyFolder.Folders("Inbox").Parent.Folders("Copy of Initiations From Team")



Thanks again.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Then once the initiation emails arrive in the shared mailbox, I am using the received time and IF statements at the beginning of the script to check from the "Copy of Initiations From Team" folder, by sorting it by date, and then taking the latest email (the first one from the of the list), and see who the last case was assigned to (John or jane). Thus giving "i" a value of 0 or 2. To then use thaa value and assign the correct category color on the subsequent new case initiations emails that come in. I couldn't think of another way of keeping track of whom the last case email was assigned to. Please feel free to suggest if this can be done in another way.
The only other way would be to write the last assigned to the registry and read - but your method is probably just as easy. I'll need to test the macro and see what its doing.
 

reubendayal

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Exchange Server 2013
The only other way would be to write the last assigned to the registry and read - but your method is probably just as easy. I'll need to test the macro and see what its doing.
That would be great!

I look forward to hearing from you.

One issue I noticed with my idea of proactively making the copy of the new case initiation emails from the OWA over to the "Copy of Initiations From Team" folder is that those emails will never get the color categories of the team, and just have the New Case category. So your suggestion of moving a copy of the processed email at the end of the script is the correct way to resolve that problem.
 

reubendayal

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Exchange Server 2013
That would be great!

I look forward to hearing from you.

One issue I noticed with my idea of proactively making the copy of the new case initiation emails from the OWA over to the "Copy of Initiations From Team" folder is that those emails will never get the color categories of the team, and just have the New Case category. So your suggestion of moving a copy of the processed email at the end of the script is the correct way to resolve that problem.
Hi Diane,

May I gently check with you if you have had a chance to test the code out?

Thank you.
 

reubendayal

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Exchange Server 2013
The only other way would be to write the last assigned to the registry and read - but your method is probably just as easy. I'll need to test the macro and see what its doing.
Hi Diane,

Sorry to chase you but have you had a chance to test the code or suggest a change in the code?

Thank you.
 

reubendayal

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Exchange Server 2013
The only other way would be to write the last assigned to the registry and read - but your method is probably just as easy. I'll need to test the macro and see what its doing.
Hi Diane,
Have you had a chance to test the macro?
Thank you.
 
Thread starter Similar threads Forum Replies Date
D Assign categories to outgoing emails Outlook VBA and Custom Forms 0
P Auto assign shared mailbox Outlook VBA and Custom Forms 1
F How to assign a task to a public task folder? Using Outlook 1
A How to assign the value returned by the regex execute function to a variable? Using Outlook 1
soadfan assign category (VBA) Using Outlook 7
Diane Poremsky Assign one task to several people New Slipstick.com Articles 0
Diane Poremsky Assign an Email Account to an Outlook Contact New Slipstick.com Articles 0
E for Mac: Assign Task not available!? Using Outlook 1
E Outlook VBA to print attached Pdf to a fax printer and assign fax number Using Outlook 0
A Assign a unique number to every message I send Using Outlook 0
Z assign unique number email Using Outlook 8
T How to Assign Retention Tags for Notes Items in Exchange/Outlook 2010? Exchange Server Administration 0
L Can you use Exchange 2010 to control which users may or may not assign tasks to other users in Outlo Exchange Server Administration 2
N Assign Task from shared Task folder error Using Outlook 3
Q Don't have right permissions to assign "send as" rights in Exchange 2010 SP1 Exchange Server Administration 7
I Outlook 2010 Archiving Assign Policy Greyed out Using Outlook 1
C How do you assign a color to emails that are only colorized if received from a specific person? Using Outlook 2
F Any way to add emails to favourites or assign shortcuts to them? Using Outlook 5
M I have added an Assign Task button to a cutom group in the Tasks Ribbon. When I click on it I get a Using Outlook 3
P Can I Assign Outlook Tasks to a Public Folder? Using Outlook 1
P Can I Assign Put a Public Folder on a Tasks's Update List? Using Outlook 5
C Y i cannot assign service to the newly added EXCHANGE certificate? Exchange Server Administration 6
C How to assign certificate(s) to an CAS array? Exchange Server Administration 1
C how should i assign an SSL certificate to a CAS array? Exchange Server Administration 2
A Outlook 2010 - assign a color category to email Using Outlook 2
D Update List clears after sending to assign person. Using Outlook 1
D assign &amp; accept tasks using an IMAP email system Using Outlook 2
M Re: Exchange 2010 Resource forest - How do you assign permissions to share linked mailboxes? Exchange Server Administration 3
M Exchange 2010 Resource forest - How do you assign permissions to share linked mailboxes? Exchange Server Administration 7
D Assign rbac to specific group does not take affect. Exchange Server Administration 15
B Exchaneg 2010 SP1 Possible Bug, Cannot create move to archive retention tag on inbox, but can create a new one and edit and assign inbox to it Exchange Server Administration 3
J Assign a signature by external or internal reciepents. Outlook VBA and Custom Forms 1
P VBA to assign category on calendar item does not work ?? why ?? Outlook VBA and Custom Forms 5
S assign task programmatically Outlook VBA and Custom Forms 2
C Cannot assign a task from a public folder? Outlook VBA and Custom Forms 4
C Assign To and CC list while using Redemption.dll library Outlook VBA and Custom Forms 10
C How to assign icon to a button in Outlook Add-in Outlook VBA and Custom Forms 1
O Calendar - appointment templates and categories Using Outlook 1
T Increasing the number of items that appear on the Categories list Using Outlook 2
Y Outlook 2013 Stop Outlook from automatically assigning categories to Tasks Using Outlook 0
B How to show concatenated categories in list task view? Using Outlook 2
D Importing Outlook Categories from another domain (Exchange 2016/Outlook 2016) Using Outlook 4
S Conditional formatting problem with "is not empty" and categories Using Outlook 2
A Outlook macro to create search folder with mail categories as criteria Outlook VBA and Custom Forms 3
P how to remove unwanted PST file default categories assigned to many calendar entries Using Outlook 7
P Import Categories from Outlook 2003 Using Outlook 8
A Outlook reverse categories Outlook VBA and Custom Forms 1
Mark Foley Color Categories on IMAP mail lost when installing new Windows 7 workstation Using Outlook 12
B VBA Macro for assigning multiple Categories to an email in my Inbox Outlook VBA and Custom Forms 1
P Task Categories Using Outlook 2
Similar threads


















































Top