7 Replies Latest reply on Oct 16, 2014 6:54 AM by cleroux

    In AFSDK UpdateValue cannot use Replace from AFUpdateOption


      Hey guys,


      Using latest versions (2014 R2), when calling UpdateValue using the Replace option from the AFUpdateOption enumeration, I am not able to replace any values (and therefore set the substitution peramater). I just don't see any reaction in the archive, as if the call was ignored. When I step into debug, the call goes through like any others. All other AFUpdateOption work using the same exact code. I can even remove the value using the Remove option too using the same code. I tried to remove and then insert, that works but the substitution flag is not set so this is not good.


      Did someone use this "Replace" mode successfully?




      Simple code I use:



          Private Sub MyCalc(ByVal alist As AFAttributeList, ByVal t As AFTime)
              Dim vs As AFValues
              'Read the values from the attributes part of alist using the GetValue() call. 
              vs = alist.GetValue(t)
              Dim badCount As Integer = 0
              For j As Integer = 0 To alist.Count - 1
                  Dim v As AFValue = vs.Item(j)
                  If v.IsGood Then
                      'Write the values back to the corresponding PIPoint DR attribute
                      alist.Item(j).Data.UpdateValue(v, Data.AFUpdateOption.Replace)
                      badCount = badCount + 1
                  End If
              Next j
          End Sub


        • Re: In AFSDK UpdateValue cannot use Replace from AFUpdateOption
          Rick Davin

          One possibility to check is that because you are asking for a specific time then alist.GetValue(t) is returning interpolated values, and not actual archive values.  If that's the case, then you are updating, you will not be replacing archive values but will instead be inserting brand new ones.

            • Re: In AFSDK UpdateValue cannot use Replace from AFUpdateOption

              Thanks Rick.


              The thing is I am able to insert perfectly values when the timestamp does not coincide with an exisitng value using the "Replace" AFUpdateOption as you are stating. When the timestamp does coincide with an exisitng value, there is no reaction in the archive. This is my issue here.


              Btw I checked the timestamp in debug and this is what happens also there (timestamp is verified to coincide with existing value --- no reaction from the system).


              Did anyone use this mode to substitute values?

                • Re: In AFSDK UpdateValue cannot use Replace from AFUpdateOption
                  Roger Palmen

                  If such a basic thing as substituting values does not work, i'd take a look at how you determine the data is not substituted.


                  What tools do you use to look at the archive? Any HA collective?

                    • Re: In AFSDK UpdateValue cannot use Replace from AFUpdateOption

                      I use System Management Tools Archive Editor plug-in. I also counter check in ProcessBook trends and in PI System Explorer (looking for the substitution flag).

                        • Re: In AFSDK UpdateValue cannot use Replace from AFUpdateOption
                          Marcos Vainer Loeff

                          Hi Christian,


                          I have tested on my VMs the code snippet below and it works fine. Not only the value is replaced but it shows on PI SMT that the same value was substituted. Could you try on your environment?



                           PIPoint myPIPoint = PIPoint.FindPIPoint(myPIServer, "sinusoid");
                                      AFTimeRange myTimeRange = new AFTimeRange("*-1d","*");
                                      AFValues myRecordedValues = myPIPoint.RecordedValues(myTimeRange, OSIsoft.AF.Data.AFBoundaryType.Inside, "", false);
                                      AFValue oldValue = new AFValue(myRecordedValues[0].Value,myRecordedValues[0].Timestamp);
                                      AFValue newValue = new AFValue(myRecordedValues[0].Value, myRecordedValues[0].Timestamp);
                                      newValue.Value = Convert.ToDouble(oldValue.Value) + 10;
                                      myPIPoint.UpdateValue(newValue, OSIsoft.AF.Data.AFUpdateOption.Replace);
                                      Console.WriteLine("Trying to change value at {0} from {1} to {2}", oldValue.Timestamp.LocalTime.ToString(), oldValue.Value.ToString(), newValue.Value.ToString());
                                      AFValue currentValue = myPIPoint.RecordedValue(myRecordedValues[0].Timestamp);
                                      Console.WriteLine("Current value after running UpdateValue: {0}",currentValue.Value.ToString());

                           Hope it helps!