4 Replies Latest reply on Jan 18, 2017 1:22 PM by MikeSpath

    Notification E-Mail Delivery Format Dilemma

      Hello everyone,

       

      First I'd like to say I'm thankful for this development forum. The contributions and provided code snippets have helped me immensely while learning the PI/AF system. I've created small applications using both the PI/AF SDKs, but I can't figure out where to begin with this problem.

       

      Here's the problem I'm running into. When a notification is converted to use delivery formatting, a new delivery format is created called "Converted Delivery Format" and each group/contact subscribed to this notification will be set to use the "Converted Delivery Format". We have a standard set and all notifications are to use the "Global Default E-Mail" format.

       

      Is there any way to efficiently change all notification delivery endpoint formats for all subscribers to all notifications? Can I access this delivery format property through an SDK and if so which one? Does anyone have any code snippets for this?

       

      Again, my goal is to set every single delivery endpoint associated with every notification to use the "Global Default E-mail" delivery format. I'd like to create an "easy button" for future use if this issue were to arise again. Manually changing thousands of notification->delivery channels is unbelievably time consuming.

       

      Thanks for the help,

       

      Nick

        • Re: Notification E-Mail Delivery Format Dilemma
          mhamel

          @Nick: Yes, you can change notification configuration (in  your case formatting) programmatically by using both PI AF SDK and PI Notifications SDK. You will need to reference these assemblies in order in your Visual Studio project:

          • OSIsoft.AF.AFSDK
          • OSIsoft.AF.UI
          • OSIsoft.AF.Security.UI
          • OSIsoft.PIAnalytics.Common
          • OSIsoft.PIAnalytics.SDK

          I added a code snippet to this post showing how to grab either a global Email Delivery Channel format or a custom format applied to a specific notification and then, apply it to a list of notifications. This will change the default format applied to your notification and also individual subscriptions in case they have been customized.

           
          'Objects.        
          Dim MyNotifList As AFNamedCollectionList(Of AFNotification)
          Dim CurrentNotif As AFNotification        
          Dim CurrentContact As AFNotificationContact
          Dim CurrentSubContact As AFNotificationContact
          Dim GlobalDCConfig As ANConfigurationNotificationGlobal = Nothing
          Dim CurrentContext As ANConfigurationNotification = Nothing
          Dim GoldenContext As ANConfigurationNotification = Nothing
          Dim GlobalEmailDCFormat As ANDeliveryFormat = Nothing
          Dim GoldenEmailDCFormat As ANDeliveryFormat = Nothing
          Dim DCFormat As ANDeliveryFormat = Nothing
          
          'Get references on collection of PI AF Servers, the right server and the
          'proper database.
          _AFServers = New PISystems
          _AFServer = _AFServers("MyServer")
          _AFDB = _AFServer.Databases("MyDatabase")
          
          'Instantiate your GlobalDCConfig object using the PISystem object.
          'This will expose the default settings of delivery channel at the PI System level.
          GlobalDCConfig = New ANConfigurationNotificationGlobal(_AFServer)
          GlobalEmailDCFormat = GlobalDCConfig.DeliveryFormats.GetDefaultDeliveryFormat(New Guid(DeliveryChannelGUIDs.Email))
          
          'Find your "golden" notification from which you want to get the format.
          MyNotifList = OSIsoft.AF.Notification.AFNotification.FindNotifications(_AFDB, "test1", OSIsoft.AF.AFSearchField.Name, OSIsoft.AF.AFSortField.Name, OSIsoft.AF.AFSortOrder.Ascending, 1)        
          
          'Get the object to handle AFNotification configuration that supports delivery formats. 
          GoldenContext = New ANConfigurationNotification(MyNotifList.Item(0))
          
          'Retrieve the default delivery format of the Email DC.
          GoldenEmailDCFormat = GoldenContext.DeliveryFormats.GetDefaultDeliveryFormat(New Guid(DeliveryChannelGUIDs.Email))
          
          'Select the global or golden DC format you like.
          DCFormat = GlobalEmailDCFormat
          'or...
          'DCFormat = GoldenEmailDCFormat
          
          'Find all notifications you want to modify
          MyNotifList = OSIsoft.AF.Notification.AFNotification.FindNotifications(_AFDB, "test2", OSIsoft.AF.AFSearchField.Name, OSIsoft.AF.AFSortField.Name, OSIsoft.AF.AFSortOrder.Ascending, 1000)
          
          For Each CurrentNotif In MyNotifList
               'Get the object to handle AFNotification configuration that supports delivery
               'formats for the current notification object.
               CurrentContext = New ANConfigurationNotification(CurrentNotif)
          
               'Set the default delivery format for this notification.
               CurrentContext.DeliveryFormats.SetDefaultDeliveryFormat(DCFormat)
          
               'Browse each subscribed contacts and change the delivery format if different
               'than the default one.
               For Each CurrentContact In CurrentNotif.NotificationContacts                
                    'CurrentContact is AFNotificationContactType.
                    Select Case True
                         Case CurrentContact.ContactType = AFNotificationContactType.Individual
                              'Modify the format if necessary.
                              CurrentContext.DeliveryFormats.SetSubscriberDeliveryFormat(CurrentContact, DCFormat)
          
                         Case CurrentContact.ContactType = AFNotificationContactType.Group, CurrentContact.ContactType = AFNotificationContactType.Escalation
                              'Modify the format at the group/escalation level.
                              CurrentContext.DeliveryFormats.SetSubscriberDeliveryFormat(CurrentContact, DCFormat)
          
                              For Each CurrentSubContact In CurrentContact.NotificationContacts
                                   'Modify the format to individuals in the group
                                   CurrentContext.DeliveryFormats.SetSubscriberDeliveryFormat(CurrentSubContact, DCFormat)
                              Next
          
                              'If you need to handle more than one level deep, add more logic for this!
                    End Select
               Next
          
               'Save changes
               CurrentContext.CommitChanges()
          
               'Check in the notification.
               CurrentNotif.CheckIn()
          Next
          

           

           

          Let me know if that helped.

            • Re: Notification E-Mail Delivery Format Dilemma

              This is exactly what I was looking for. Thanks a lot, Mathieu.

                • Re: Notification E-Mail Delivery Format Dilemma
                  Mike Zboray

                  Hey Nick,

                   

                  I just wanted to add that in the most recent version of Notifications (2012, 1.2.1205.10) there are more options for conversion to delivery formatting. One of which corresponds to your scenario of always using the global default. In PSE when you convert, you are now prompted to select an option when converting, one of which is "Send the global default content to all subscribers". If you are doing the conversion in code you would call the ConvertToDeliveryFormatting method with the NoAutoCreatedFormats option.

                   
                  foreach(var notification in notificationList)
                  {
                    if (notification.Template != null) continue; // Notifications from template should be handled separately at the template level.
                  
                    ANConfigurationNotification context = new ANConfigurationNotification(notification);
                    context.ConvertToDeliveryFormatting(ANDeliveryFormats.ConversionType.NoAutoCreatedFormats);
                    context.CommitChanges();
                    notification.CheckIn();
                  }
                  
                  

                  Of course, if you've already done the conversion then you will have to set it for each notification.

                   

                  Also, Delivery Formatting has this idea of inheriting a default from some higher level context that can be layered in complex ways. If your desire is to set each subscription explicitly then Mathieu's solution is correct. You should be aware that by setting each subscription explicitly you are 'locking in' your choice everywhere. To change subscriptions again it will be require going to each subscription (either in code or by hand) and changing it. We weren't sure this was desirable from a maintainability view point so there is no built in way to do it. The inheritance mechanism can be used to change the default for only particular notifications or templates and is therefore favored if you might want to configure specific notifications or templates differently than the rest.

                   

                  Mike