1 Reply Latest reply on Mar 29, 2018 10:05 PM by David Hearn

    How can I add an existing AF contact to an existing Notification (or Notification Template)?


      I have written the following code:


              Dim contacts As OSIsoft.AF.AFNamedCollection(Of OSIsoft.AF.AFContact)
              contacts = OSIsoft.AF.AFContact.FindContacts(AFSys, principal.Name, OSIsoft.AF.AFSearchField.Name, OSIsoft.AF.AFSortField.Name, OSIsoft.AF.AFSortOrder.Ascending, 10)
              If contacts.Count > 0 Then
                  cTemplate = AFSys.NotificationContactTemplates.Item(contacts(0).Name)
                  If cTemplate Is Nothing Then
                      cTemplate = New OSIsoft.AF.Notification.AFNotificationContactTemplate(contacts(0), principal.Name)
                      cTemplate.DeliveryChannelPlugIn = AFSys.DeliveryChannelPlugIns("Email")
                  End If
                  eTemplate = AFDB.ElementTemplates.Where(Function(template) template.Name = elementtemplatename)(0)
                  If eTemplate IsNot Nothing Then ' this is a template
                      notificationTemplate = AFDB.ElementTemplates(elementtemplatename).NotificationRuleTemplates(notificationname)
                      ruleSubscriber = notificationTemplate.Subscribers.Add(cTemplate)
                  Else ' this is an element
                      ruleSubscriber = AFDB.Elements(elementtemplatename).NotificationRules(notificationname).Subscribers.Add(cTemplate)
                  End If
                  AddUser = "Username: " & username & " Not Found in AF Contacts Database"
              End If


      But it gives the following error:


      Error Adding User to Notification: Exception in AddUser: Cannot complete the operation because the user does not have rights to write to NotificationContactTemplate 'UserID' with UniqueID '9eb73cf7-7c83-4a71-9b96-4f4b45097d07'.

      I have full access to the AF database.


      I can't seem to find a relevant code example in the AF documentation.