AFListData.UpdateValues Method (IList(AFValue), AFUpdateOption)
- Last UpdatedJan 12, 2026
- 5 minute read
- PI System
- AF SDK 3.2.0
- Developer
Namespace: OSIsoft.AF.Data
Assembly: OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.2.0.7
Syntax
public static AFErrors<AFValue> UpdateValues( IList<AFValue> values, AFUpdateOption option )
Public Shared Function UpdateValues ( values As IList(Of AFValue), option As AFUpdateOption ) As AFErrors(Of AFValue) Dim values As IList(Of AFValue) Dim option As AFUpdateOption Dim returnValue As AFErrors(Of AFValue) returnValue = AFListData.UpdateValues(values, option)
public: static AFErrors<AFValue^>^ UpdateValues( IList<AFValue^>^ values, AFUpdateOption option )
static member UpdateValues : values : IList<AFValue> * option : AFUpdateOption -> AFErrors<AFValue>
Parameters
- values
- Type: System.Collections.GenericIListAFValue
The list of values with an associated AFAttribute for each value. - option
- Type: OSIsoft.AF.DataAFUpdateOption
An enumeration value that specifies how to treat duplicate values. It can also be used to specify that an existing value should be removed.
Return Value
Type: AFErrorsAFValueReturns a list of the errors associated with the AFValue that caused the error. If there are no errors, then is returned.
Remarks
This method will take the list of values with an associated AFAttribute and update multiple values for multiple attributes. Multiple values for the same AFAttribute can be in the list. The value cannot be updated if the AFValue.Attribute is not defined.
For the case of attributes which are configuration items, this method (unlike AFAttribute.SetValue) does not require the corresponding AFElement to be checked out or checked in.
If not specified in AFSDK.config, the AFBufferOption is defaulted to BufferIfPossible. The default buffering option for the current AF SDK client instance can be modified via the static property AFData.BufferOption.
| For the case of attributes that do not have a data reference and which are configuration items, if the corresponding AFElement is already checked out by another user (i.e. through AFAttribute.SetValue) when this method is called, then the value(s) to update may be lost when the other user checks in the AFElement. |
Examples
// This example demonstrates how to update multiple values using // the AFListData.UpdateValues method // Get the Database and UOMs PISystems myPISystems = new PISystems(); PISystem myPISystem = myPISystems.DefaultPISystem; AFDatabase myDB = myPISystem.Databases.DefaultDatabase; UOM uomYard = myPISystem.UOMDatabase.UOMs["yard"]; UOM uomSqFoot = myPISystem.UOMDatabase.UOMs["square foot"]; UOM uomLiter = myPISystem.UOMDatabase.UOMs["liter"]; // Create the Element AFElement myElement = myDB.Elements.Add("MyElement"); AFAttribute myAttribute = myElement.Attributes.Add("MyAttribute"); myAttribute.Type = typeof(double); myAttribute = myElement.Attributes.Add("MyAttribute2"); myAttribute.Type = typeof(double); // Create List of Attributes and their new values AFTime newTime = new AFTime("T-1d", CultureInfo.CurrentCulture); AFAttributeList attrList = new AFAttributeList(); List<AFValue> newValues = new List<AFValue>(); Random randomValues = new Random(); // Create Dynamic Attribute to a PIPoint to Update PIServer piServer = PIServers.GetPIServers().DefaultPIServer; if (PIPoint.TryFindPIPoint(piServer, "MyTestPoint#1", out PIPoint point)) { myAttribute = new AFAttribute(point); myAttribute.DefaultUOM = uomLiter; myAttribute.ConfigString += ";ReadOnly=False"; attrList.Add(myAttribute); newValues.Add(new AFValue(myAttribute, randomValues.NextDouble(), newTime, uomLiter)); } if (PIPoint.TryFindPIPoint(piServer, "MyTestPoint#2", out point)) { myAttribute = new AFAttribute(point); myAttribute.DefaultUOM = uomYard; myAttribute.ConfigString += ";UOM=ft;ReadOnly=True"; attrList.Add(myAttribute); newValues.Add(new AFValue(myAttribute, randomValues.NextDouble(), newTime, uomYard)); } // Get some Attributes from the Element to Update myAttribute = myElement.Attributes["MyAttribute"]; attrList.Add(myAttribute); newValues.Add(new AFValue(myAttribute, 100, newTime, uomSqFoot)); myAttribute = myElement.Attributes["MyAttribute2"]; attrList.Add(myAttribute); newValues.Add(new AFValue(myAttribute, 200, newTime, null)); // Get the Current Values for the Attributes AFValues currentValues = attrList.GetValue(newTime); Console.WriteLine("Current Values:"); foreach (AFValue value in currentValues) { Console.WriteLine(" {0}: '{1} {2}' at '{3}'", value.Attribute, value.Value, value.UOM, value.Timestamp); } // Update the Attribute Values and Display any Errors AFErrors<AFValue> errors = AFListData.UpdateValues(newValues, AFUpdateOption.Replace); if (errors != null && errors.HasErrors) { Console.WriteLine("\nErrors returned from AFListData.UpdateValues:"); // Display Value errors if (errors.Errors != null && errors.Errors.Count > 0) { foreach (var item in errors.Errors) { Console.WriteLine(" AFValue '{0}': {1}", item.Key, item.Value); } } // Display error from the PI Data Archive if (errors.PIServerErrors != null && errors.PIServerErrors.Count > 0) { foreach (var item in errors.PIServerErrors) { Console.WriteLine(" AFValue '{0}': {1}", item.Key, item.Value); } } // Display PI System errors if (errors.PISystemErrors != null && errors.PISystemErrors.Count > 0) { foreach (var item in errors.PISystemErrors) { Console.WriteLine(" AFValue '{0}': {1}", item.Key, item.Value); } } } // Get the Updated Current Values for the Attributes currentValues = attrList.GetValue(newTime); Console.WriteLine("\nUpdated Current Values:"); foreach (AFValue value in currentValues) { Console.WriteLine(" {0}: '{1} {2}' at '{3}'", value.Attribute, value.Value, value.UOM, value.Timestamp); }