none
Outlook 2010 AutoFormatRule.Filter property not saving RRS feed

  • Question

  • I am writ a script to create a custom property in Outlook for a customer and then apply conditional formatting to the Inbox based on the custom property. To this point I have been able to create the property, add it to the view and set the custom formatting. The only issue that I am having is that the Filter property on the format rule is not applying, so the format gets applied to all items.

    The PowerShell script to perform this is below:

    Add-Type -AssemblyName "Microsoft.Office.Interop.Outlook"
    $Outlook = New-Object -ComObject Outlook.Application
    $Inbox = ($Outlook.GetNameSpace("MAPI")).GetDefaultFolder([Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderInbox)
    
    # Create the Objective column if it doesn't exist
    If (-Not ($Inbox.UserDefinedProperties | Where Name -eq "Objective")) {
        $Inbox.UserDefinedProperties.Add("Objective", [Microsoft.Office.Interop.Outlook.OlUserPropertyType]::olYesNo, [Microsoft.Office.Interop.Outlook.OlFormatYesNo]::olFormatYesNoIcon)
    }
    
    For ($i = 1; $i -le $Inbox.Views.Count; $i++) {
        $View = $Inbox.Views.Item($i)
        
        # Add Objective field to each view
        $ViewField = $View.ViewFields | Where ViewXMLSchemaName -match "Objective"
        If (-Not $ViewField) { $ViewField = $View.ViewFields.Insert("Objective",2); $View.Save() }
    
        # Add Objective formatting to each view
        $Rule = $View.AutoFormatRules | Where Name -eq "Objective"
        If (-Not $Rule) { $Rule = $View.AutoFormatRules.Add("Objective") }
    
        $Rule.Filter = "`"$($ViewField.ViewXMLSchemaName)`" = 1"
        $Rule.Font.Strikethrough = $true
        $Rule.Font.Color = [Microsoft.Office.Interop.Outlook.OlColor]::olColorBlue
    
        # Commit the changes
        $View.AutoFormatRules.Save()
        $View.Save()
        If ((Get-Process -Name OUTLOOK -ErrorAction SilentlyContinue) -And ($Inbox.CurrentView.Name -eq $View.Name)) { $View.Apply() }
    }
    

    I have tried setting the filter parameter both with the variable (as above) and as a direct string ("http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/Objective" = 1) which I copied from a manually created rule doing the same.

    I have tested this script on both Outlook 2010 (intended target version) on Windows 7 x64 and Outlook 2013 on Windows 7 x86 with the same result.

    • Moved by Max Meng Wednesday, May 15, 2013 5:51 AM
    Tuesday, May 14, 2013 11:47 PM

Answers

  • I raised a premier call in response to this issue. The response was that it is a known bug in the Outlook Object Model. It will not be fixed in Outlook 2010 or Outlook 2013 as the risk is too great for the small change.

    The workaround solution that Microsoft provided was to copy a rule from a Public Folder to the user's profile.

    • Marked as answer by oWretch Tuesday, July 2, 2013 11:17 PM
    Tuesday, July 2, 2013 11:17 PM

All replies

  • Hi ,

    Thank you for posting in the MSDN Forum.

    I'm trying to involve some senior engineers into this issue and it will take some time. Your patience will be greatly appreciated.

    Sorry for any inconvenience and have a nice day!

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, May 16, 2013 1:01 PM
    Moderator
  • Thanks for that Quist.

    Is there an internal reference that I can quote for this? The customer is keen to have the issue resolved so I am looking at raising a PSS call for it. If the issue is already being tracked internally it would be good to link it to that.

    Regards

    Jerome

    Monday, May 27, 2013 4:36 AM
  • Hi,

    Have you tried to reproduce this issue with VBA code or have you tried this with Outlook UI?

    Regards,

    Shailesh G. Rajput
    ______________________________________________
    Microsoft Developer Support - Messaging & Collaboration
     


    Tuesday, July 2, 2013 9:14 PM
  • I raised a premier call in response to this issue. The response was that it is a known bug in the Outlook Object Model. It will not be fixed in Outlook 2010 or Outlook 2013 as the risk is too great for the small change.

    The workaround solution that Microsoft provided was to copy a rule from a Public Folder to the user's profile.

    • Marked as answer by oWretch Tuesday, July 2, 2013 11:17 PM
    Tuesday, July 2, 2013 11:17 PM
  • Hi Jerome,

    Thanks for the update and posting the answer on the thread.


    Regards,

    Shailesh G. Rajput
    ______________________________________________
    Microsoft Developer Support - Messaging & Collaboration
     

    Friday, July 5, 2013 5:04 PM
  • I have Office 365 (2016) and it's still not working.

    Formatting works (sort-of), but when you open the wizard, the conditions (.filter) are gone.

    • Proposed as answer by Mauro F_ Friday, January 19, 2018 1:07 PM
    • Unproposed as answer by Mauro F_ Friday, January 19, 2018 1:07 PM
    Tuesday, January 16, 2018 2:57 PM
  • A possible workaround:

    - customize manually a view with all formatting conditions (i.e. the _model_)

    - clone that view (instead of creating a new one)

    - customize the cloned view

    In VBA, that would result in:

    set modelview= ActiveExplorer.CurrentFolder.Views("_model_")
    set newview = modelview.Copy("newviewname", olViewSaveOptionAllFoldersOfType)
    Customize(newview)
    newview.Apply

    Not tested, but might work, grabbing the model view from a customized PST.



    • Proposed as answer by Mauro F_ Friday, January 19, 2018 1:13 PM
    Friday, January 19, 2018 1:12 PM