3 Replies Latest reply on Oct 27, 2016 4:11 PM by dpilc

    How to store NULLs in AF?


      Hello Everyone,


      I want to store in AF in attributes NULL values. How can i do it? What is more, I need to do it using AFSDK.

      In AFSDK documentation I found this information(https://techsupport.osisoft.com/Documentation/PI-AF-SDK/Html/M_OSIsoft_AF_Asset_AFAttribute_SetValue_3.htm):

      The new AFValue object for the attribute's value. If the AFValue.Value is DBNull.Value, then the attribute's value will be reset back to using the default value from the template. A value of DBNull.Value is not allowed if the attribute does not have a Template defined. UOMValueDefaultUOMValuePointType

      The problem is here: how to set in AF values to be NULL by default? If it is not possible how can i achieve the goal to store somehow information, that the attribute has not been yet set.


      Kind Regards,


        • Re: How to store NULLs in AF?
          Rick Davin

          Hi Dawid,


          I'd strongly encourage one to use a SYSTEM digital state rather than a null.


          See AFSystemStateCode Enumeration


          See AFValue.CreateSystemStateValue


          Older versions of AF SDK allowed a null to be stored for doubles, singles, ints, etc., but only if the value status was bad.


          Neither of these will work for you:


          var value = new AFValue(null, time, uom: null, status: AFValueStatus.Bad);


          var value = new AFValue(DBNull.Value, time, uom: null, status: AFValueStatus.Bad);


          However, does it really have to be DBNull or null?  If all you want to see is nothing or blanks instead of a 0, then there is an alternative.  This alternative works for attributes with a null DataReferencePlugIn, but also be aware that a red flag appears in PSE.


          //This works but there will be a red flag by the bad value
          var value = new AFValue("", time, uom: null, status: AFValueStatus.Bad);


          Before, using default 0 values:

          2016-10-26 09_19_01-__RDAVIN7250_Null AFValue Example - PI System Explorer (Administrator).png


          After, forcing a blank:

          2016-10-26 09_19_27-Null AFValue Example (Running) - Microsoft Visual Studio.png


          Because the data type of the value does not match the data type of the attribute, a red flag appears.  { Alan Kenyon  you might find this interesting as a follow up to an older thread we participated in. }


          All that said and done, let's not focus on force fitting some null or equivalent, but instead focus on your last question:


          If it is not possible how can i achieve the goal to store somehow information, that the attribute has not been yet set.


          At mentioned in very beginning, use a SYSTEM state instead.  Perhaps:








          You would still get a bad flag but it would be gray instead of red.  But the value displayed would also have a bit more text to catch your eye.


          Using SYSTEM State


          The code would look something like:

          var value = AFValue.CreateSystemStateValue(AFSystemStateCode.InvalidData, time);


          And the result would be:


          2016-10-26 09_49_08-__RDAVIN7250_Null AFValue Example - PI System Explorer.png

          1 of 1 people found this helpful
            • Re: How to store NULLs in AF?

              I have just added a comment to another post, which might also be worth looking at. If you use a system digital state then in any operations on data you can use BadVal() to catch these items in an Analyses, which will help avoid a Calc Failed message.

              Hello Everyone, is there a way to put animation om a pump based on the changing values of the speed tag; the propeller rotates when the rpm of the speed is greater than zero in PI Processbook else remains static.

              • Re: How to store NULLs in AF?

                Thanks for your responses!

                I've tried to use AFValueStatus as you mentioned and it partially solves my problem. Some of attributes I use in analysis(Expression and Rollup).

                I've prepared simple Expression Analysis: "<attribute of numeric type> + 1"

                I discovered that in "Expression Analysis" calculations on Attributes with AFValueStatus.Bad causes "Calc Failed" with description "Invalid operation: [error] + [number]". In Rollup Analysis defined in parent node(sum of the attribute for all children) those with AFValueStatus.Bad were ignored.

                The flag I tested next was AFValueStatus.Questionable. I noticed that I was able to set value for the attribute, e.g. 20. Ok, it's Questionable not Bad. In Expression Analysis with the same equation I got an error "Invalid operation: [number] + [number]", but for Rollup Analysis it succeeded and added 20 to the sum.

                Why it behaves like that?


                Details of AF scheme I used to tests:

                - Root node with 3 children

                      - Child 1

                          - A = 1, no status

                     - Child 2

                          - A = 10, Bad

                     - Child 3

                          - A = 100, Questionable

                - Each child of template with attributes:


                - Analysis on template:

                     - Expression Analysis 1:

                          'A' + 1- Analysis on root element:

                     - Rollup Analysis 1:

                          Rollup attributes of child elements with selected attribute 'A' and selected functions Sum and Count.