Supress long timestamp in Notifications

Document created by mikespath on Jan 12, 2017
Version 1Show Document
  • View in full screen mode

Hello fellow AF SDKers:

I would like to take the time to explain a recent service call I had and how it was resolved in hopes it may help others.

ISSUE: I work with Notifications via the SDK but first I have to perform the tasks in the PI SystemExplorer UI. I could not find out how to supress the long time format in all of my Notification e-mail outputs.

EXAMPLE: the line in my e-mail that displayed timestamps looked like: Start Time: 09-Jan-2017 11:24:00 AM Eastern Standard Time (GMT-05:00:00)

DESIRED OUTPUT: Start Time: 09-Jan-2017 11:24:00 AM

ACTION: Called into tech support and talked with Santosh Koirala and he opened Case # 761966: Suppress Time Zone from Trigger time and display fewer digits in numerical values in Notification 2016

RESOLUTION: After he had done research on the OSI end he found that you can add an Attribute named "TimeFormat" to dictate the format. The location of this attribute is:

\\Configuration\OSIsoft\PIANO

\\Configuration\OSIsoft\PIANO\Notifications\Service    

Below is a method I wrote in my test application that uses the AF SDK to perform this change. I wanted to add this as a discussion document before I posted the code on PI Square in an effort to improve it.

 

        /// <summary>

        /// Method usually called only at configuration to setup to supress the Notification timestamps of using timezones

        /// </summary>

        /// <param name="strNewFormat"></param> new format such as "dd/mm/yyyy hh:mm:ss tt"

        /// <param name="strAFDatabase"></param> "Configuration"

        /// <param name="strParentElement"></param> OSIsoft or OSIsoft\\PIANO\\Notifications

        /// <param name="strChildElement"></param> PIANO or Service

        private void ChangeTimeFormatNotif(string strNewFormat, string strAFDatabase, string strParentElement, string strChildElement)

        {

            var db = MyPISystem.Databases[strAFDatabase];

 

            AFSearchToken rootToken = new AFSearchToken(AFSearchFilter.Root, AFSearchOperator.Equal, db.Elements[strParentElement].GetPath());

            AFSearchToken descToken = new AFSearchToken(AFSearchFilter.AllDescendants, AFSearchOperator.Equal, "false");

            AFElementSearch elementSearch = new AFElementSearch(db, "FindChildElements", new[] { rootToken, descToken });

            elementSearch.CacheTimeout = TimeSpan.FromMinutes(10); // Opt in to server-side caching 

 

            IEnumerable<AFElement> elements = elementSearch.FindElements(0, false, 1000);

            foreach (AFElement element in elements)

            {

                if (element.Name.Contains(strChildElement))

                {

                    var chkTimeAtt = element.Attributes["TimeFormat"];

                    if (chkTimeAtt == null)

                    {

                        AFAttribute timeAtt = element.Attributes.Add("TimeFormat");

                        AFValue v = new AFValue(strNewFormat);

                        timeAtt.SetValue(v);

                        timeAtt.Type = typeof(string);

                        element.CheckIn();

                    }

                }

            }// end of method

Attachments

    Outcomes