none
Outlook 2016 bug : vba GetRules() does not return an items list when rules for another computer exist RRS feed

  • Question

  • Application.Session.DefaultStore.GetRules() returns an object with the correct number of rules in it, however if there is a rule that is "For other computer",  it is not returning the items list and the rules cannot be parsed. 

    Is there any way to notify an engineer at Microsoft  and have this fixed ?


    • Edited by J. Farro Wednesday, May 17, 2017 6:02 AM
    • Moved by Steve Fan Thursday, May 18, 2017 2:49 AM
    Wednesday, May 17, 2017 5:58 AM

All replies

  • Hi,

    Since this forum is for general questions and feedback related to Microsoft Office client, I'll move your question to a more appropriate forum:

    https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=outlookdev

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

    Regards,

    Steve Fan


    Please remember to mark the replies as answers if they helped.

    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    • Marked as answer by J. Farro Thursday, May 18, 2017 5:59 AM
    • Unmarked as answer by J. Farro Thursday, May 18, 2017 6:00 AM
    Thursday, May 18, 2017 2:49 AM
  • Hello,

    What is your build number of Office?

    >>  it is not returning the items list and the rules cannot be parsed

    What do you want to return?

    By watching the rules object, I could see the rule which is for other computer.

    I am using build 7369.2130.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, May 18, 2017 9:22 AM
    Moderator
  • Hello Celeste

    Using Outlook 2016, Version 1703, Build 7967.2161

    I am using the following vba code:

        Set colRules = Session.DefaultStore.GetRules()
    
        For Each oRule In colRules
            ruleName = oRule.Name
            If Left(ruleName, 21) = "AutoCategorize into " Then
                oRule.Execute (True)
            End If
        Next

    It bombs on the line: 

    For Each oRule In colRules

    The problem, according to my debugging, is in the returned colRules object. On the computer where some rules show as "For other computer",  I have Outlook 2016 and the debugger shows it has 26 items, but contains none:

    On the computer where the rules were generated I have Outlook 2013 and the debugger shows the same 26 rules, only this time all items are there:


    When debugged this, I saw that if I removed all the foreign rules (those for other computer), then the code works, returning a colRules object with viewable items, albeit with fewer rules.

    Continued debugging today and noticed that even though the colRules object did not show any items, I was able to extract the non-foreign rules if I knew what index they were. On the other hand, accessing any foreign rule through index would yield an error:  "The attempted operation failed, an object could not be found".



    I changed my code to use a for loop to go over the items and set vba to skip over errors. I was able to list all the non-foreign rules ok, with the following code:

    Set colRules = Application.Session.DefaultStore.GetRules() On Error Resume Next For i = 1 To colRules.Count Set oRule = colRules.Item(i) If Not oRule Is Nothing Then

    ruleName = oRule.Name If Left(ruleName, 21) = "AutoCategorize into " Then oRule.Execute (True) End If Set oRule = Nothing End If Next On Error GoTo 0

    The questions now are:

    1. Why are the foreign rules not exposed through the vba model? could it be a security issue?
    2. Does any particular flag or property needs to be set to allow seeing them?







    • Edited by J. Farro Thursday, May 18, 2017 11:41 PM Added images and code
    Thursday, May 18, 2017 4:53 PM
  • Hello,

    Testing in Build 8201.2025(Insider version) and Build 8067.2115 from current channel, I could see the item lists.

    According to Version and build numbers of update channel releases , the version you are using now is not the latest,

    I suggest you update to Build 8067.2115.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, May 19, 2017 9:28 AM
    Moderator
  • Hello again Celeste,

    I updated outlook. I now have Version 1704, Build 8067.2115, as yours, yet the problem still exists.

    Here is a debugger screenshot that shows I have now 51 rules- but none of them are visible. (I added more rules since my previous experiments, some local and some on other computer):

    Something else is going on if you can see them and I can't. Any ideas as to what to look for?


    • Edited by J. Farro Friday, May 19, 2017 10:50 PM
    Friday, May 19, 2017 10:49 PM
  • Hello,

    I could reproduce the issue once. I think the issue causes from a specific rule.

    In PC2, I add 15 rules and there are 10 rules on this computer only. I failed to see the item lists in the computer PC1. I then remove the rules one by one in PC2 and watch the rules in PC1. I could see the item list when there are 8 rules. Then in PC2, i begin to add rules and check the rule in PC1. This time i failed to reproduce the issue. (The rules are always could displaying when the rule number grows to 17 including 11 rules for other computer)Since i am creating the rule randomly, so i think the issue causes from specific rule.

    I suggest you back your rules up and remove one by one to check which rule causes the issue.

    Besides, i check the Outlook Object model, i think it doesn't provide any method to work around the issue. I think we need to find out which rule causes the issue and remove it from the list.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, May 22, 2017 7:03 AM
    Moderator
  • Celeste,

    There is nothing wrong with the rules I have. I checked them one by one- each one runs OK.

    All the rules that are specific to a computer are created pragmatically. They are all the exact same rule with different parameters. The only common denominator is that they are all for another computer. Maybe because the rules were created on the other computer with outlook 2013, and on the new one has outlook 2016 they are not showing up. I will be able to test this theory when I recreate the rules on another computer that runs also outlook 2016.

    Tuesday, May 30, 2017 5:44 AM
  • Hello,

    The code below is used to create 20 rules LocalMachineOnly and 20 rules for all computers.

    I would suggest you remove all your rules and test the code below and check if you could see the item list.

    i create 60 rules using the code and could see the rule lists on other computer. (both Outlook 2016) If it doesnt work for you, i think your issue causes from your environment. 

    If you could see the item list, it indicates the issue causes from the specific rule(s). Since the code just specify the From condition, you could create similar rules with your certain conditions and actions. Please visit Rules.Create Method (Outlook)

    Sub createRules()
    Dim i As Integer
    Dim colRules As Outlook.Rules
    Dim oRule As Outlook.Rule
    Dim colRuleActions As Outlook.RuleActions
    Dim oMoveRuleAction As Outlook.MoveOrCopyRuleAction
    Dim oFromCondition As Outlook.ToOrFromRuleCondition
    Dim oExceptSubject As Outlook.TextRuleCondition
    Dim oInbox As Outlook.Folder
    
    Set oInbox = Application.Session.GetDefaultFolder(olFolderInbox)
    Set colRules = Application.Session.DefaultStore.getRules()
    For i = 1 To 40
    Set oRule = colRules.Create("TestRule" & i, olRuleReceive)
    Set oFromCondition = oRule.Conditions.From
    With oFromCondition
    .Enabled = True
    .Recipients.Add ("test" & i)
    End With
    If i Mod 2 = 0 Then
    oRule.Conditions.OnLocalMachine.Enabled = True
    End If
    Next i
    colRules.Save
    End Sub

    Regards,

    Celeste



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, May 31, 2017 9:30 AM
    Moderator