3 Replies Latest reply on Oct 28, 2014 8:39 PM by aommeren

    Create a Notification Comment from code

    aommeren

      Hello,

       

      I am trying to get my pieces together to solve the following puzzle :

       

      The intention is to use PI Notifications to send maintenance alerts to the Maintenance system (SAP-PM). The idea is to use the XML delivery channel which I am trying to code at this very moment. These will be processed by the SAP interface/middleware.
      Thinking ahead already....: the XML or Webservice DC's are basically fire and forget. I will propose to close the loop and store the feedback from SAP (the Notification ID or potential error) as a comment on the Notification (instance).

       

      This async response can be made available in several ways I expect. My question is about :
      - What information should be available to write the comment programmatically ? Notification ID (The GUID) and instance ID, ... ? I guess the AF or AN method will describe the needs.
      - Are there code samples around that describe how I can do this (I prefer VB.NET) - already looking at other posts and the AF- and AN SDK help files, but I can use some help and direction here 

       

      Thanks!

       

      Ad

       

       

       

       

       

       

        • Re: Create a Notification Comment from code
          Mike Zboray

          Hi Ad,

           

          You'll want to use ANNotification.AddComment to add a comment to a notification. Here's a short sample: 

           
                  private static void AddComment(AFNotification notification, AFNotificationContactTemplate nct, string comment)
                  {
                      string errorMessage;
                      int instanceId = -1; // use -1 for most recent instance.
                      if (ANNotification.AddComment(notification, instanceId, nct.ID, comment, out errorMessage))
                      {
                          Console.WriteLine("Comment added successfully.");
                      }
                      else
                      {
                          Console.WriteLine("Failed to add comment: {0}", errorMessage);
                      }
                  }
          

           A few notes:

           

          You can provide -1 as the instance id if you want to comment on the current instance. 

           

          The 3rd parameter is named contactId, however I am fairly certain it admits both the AFNotificationContactTemplate's Id (which I used above) or the AFContact's Id.

           

          One caveat to this is that you cannot comment or acknowledge from within the delivery channel's send method. The reason is that there is a lock taken when calling this method that will need to be taken in order to comment. It should be fine if you send over to SAP, then at some point later comment/ack (out-of-process), but within Send a AddComment or AcknowledgeSubcription call will timeout.