3 Replies Latest reply on Mar 27, 2015 12:07 PM by AlistairFrith

    Manually setting the substituted flag in AFListData.UpdateValues


      I am using AF to replace a batch of historical values. Usually they will completely match with the current values but sometimes they won't. So I am deleting the existing values first. This means that when I add the new values, the Substituted flag won't be set, so I need to manually set it. However, I don't seem to be able to do this.


      If I do

         // add new AF Value into the results table  
         AFValue newVal = new AFValue((AFAttribute)analysisRow.Attribute, calcRes.Value, calcRes.Timestamp);
        newVal.Substituted = true;


      (Stupid editor! Maybe it will be readable to you once I post it) then when I do

        errors = AFListData.UpdateValues(results, AFUpdateOption.Replace);


      The values go in but are not marked as Substituted


      If on the other hand I do

         AFValue newVal = new AFValue((AFAttribute)analysisRow.Attribute, calcRes.Value, calcRes.Timestamp, null, AFValueStatus.Substituted);


      Then the values all go in as "Set To Bad" digital states rather than the proper values. What is going on and how can I set the Substituted flag?



      --- Alistair







        • Re: Manually setting the substituted flag in AFListData.UpdateValues

          Hi Alistair,


          Starting with PI Data Archive 3.4 and above, you cannot manually set the substituted flag. This flag is set by the system during editing and cannot be directly set or cleared by the user. Only changes to the value itself are considered substitution. Please refer to KB 3030OSI8 for more information.


          My advice would be grabbing the existing AFValue from your attribute, change the value property of the AFValue, and call UpdateValue with AFUpdateOption.Replace. This way, you can replace the existing value and the PI system will take care of setting the substituted flag.

          • Re: Manually setting the substituted flag in AFListData.UpdateValues

            Hi Alistair,


            Daphne pointed out very good information. From the KB:

            2. The substituted flag is set only when the value actually changes. In previous releases, it was set by any editing operation, even if the value did not change or only the flags were set.


            So, in case you really need to delete all values first, a workaround could be to insert two values a the same time afterwhile. I tested this and it works:

                        var time = AFTime.Parse("*-5m");
                        values.Add(new AFValue(0, time));
                        values.Add(new AFValue(10, time));
                        TagA.UpdateValues(values, AFUpdateOption.Replace);


            One remark is that if your values are all the same the substituted flag will not change.


            Hope this helps!