Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AF SDK Reference

AFListData.UpdateValues Method (IList(AFValue), AFUpdateOption)

AFListData.UpdateValues Method (IList(AFValue), AFUpdateOption)

  • Last UpdatedNov 18, 2025
  • 7 minute read
AFListData.UpdateValues Method (IList(AFValue), AFUpdateOption)
Write, update, or remove a AFAttribute value for each AFValue in the specified list.

Namespace:  OSIsoft.AF.Data
Assembly:  OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.1.1.1182

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: AFErrorsAFValue
Returns 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.

Important note Important
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);
}
' This example demonstrates how to update multiple values using
' the AFListData.UpdateValues method

' Get the Database and UOMs
Dim myPISystems As PISystems = New PISystems
Dim myPISystem As PISystem = myPISystems.DefaultPISystem
Dim myDB As AFDatabase = myPISystem.Databases.DefaultDatabase
Dim uomYard As UOM = myPISystem.UOMDatabase.UOMs("yard")
Dim uomSqFoot As UOM = myPISystem.UOMDatabase.UOMs("square foot")
Dim uomLiter As UOM = myPISystem.UOMDatabase.UOMs("liter")

' Create the Element
Dim myElement As AFElement = myDB.Elements.Add("MyElement")
Dim myAttribute As AFAttribute = myElement.Attributes.Add("MyAttribute")
Dim someType As Type = GetType(Double)
myAttribute.Type = GetType(Double)
myAttribute = myElement.Attributes.Add("MyAttribute2")
myAttribute.Type = GetType(Double)

' Create List of Attributes and their new values
Dim newTime As AFTime = New AFTime("T-1d", CultureInfo.CurrentCulture)
Dim attrList As AFAttributeList = New AFAttributeList
Dim newValues As List(Of AFValue) = New List(Of AFValue)
Dim randomValues As Random = New Random

' Create Dynamic Attribute to a PIPoint to Update
Dim piServer As PIServer = PIServers.GetPIServers.DefaultPIServer
Dim point As PIPoint = Nothing
If PIPoint.TryFindPIPoint(piServer, "MyTestPoint#1", point) Then
    myAttribute = New AFAttribute(point)
    myAttribute.DefaultUOM = uomLiter
    myAttribute.ConfigString = (myAttribute.ConfigString + ";ReadOnly=False")
    attrList.Add(myAttribute)
    newValues.Add(New AFValue(myAttribute, randomValues.NextDouble, newTime, uomLiter))
End If
If PIPoint.TryFindPIPoint(piServer, "MyTestPoint#2", point) Then
    myAttribute = New AFAttribute(point)
    myAttribute.DefaultUOM = uomYard
    myAttribute.ConfigString = (myAttribute.ConfigString + ";UOM=ft;ReadOnly=True")
    attrList.Add(myAttribute)
    newValues.Add(New AFValue(myAttribute, randomValues.NextDouble, newTime, uomYard))
End If

' 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, Nothing))

' Get the Current Values for the Attributes
Dim currentValues As AFValues = attrList.GetValue(newTime)
Console.WriteLine("Current Values:")
For Each value As AFValue In currentValues
    Console.WriteLine("  {0}: '{1} {2}' at '{3}'", value.Attribute, value.Value, value.UOM, value.Timestamp)
Next

' Update the Attribute Values and Display any Errors
Dim errors As AFErrors(Of AFValue) = AFListData.UpdateValues(newValues, AFUpdateOption.Replace)
If (Not errors Is Nothing AndAlso errors.HasErrors) Then
    Console.WriteLine("Errors returned from AFListData.UpdateValues:")

    ' Display Value Errors
    If (Not errors.Errors Is Nothing AndAlso errors.Errors.Count > 0) Then
        For Each item As KeyValuePair(Of AFValue, Exception) In errors.Errors
            Console.WriteLine("  AFValue '{0}': {1}", item.Key, item.Value)
        Next
    End If

    ' Display PI Data Archive Errors
    If (Not errors.PIServerErrors Is Nothing AndAlso errors.PIServerErrors.Count > 0) Then
        For Each item As KeyValuePair(Of PIServer, Exception) In errors.PIServerErrors
            Console.WriteLine("  AFValue '{0}': {1}", item.Key, item.Value)
        Next
    End If

    ' Display PI System Errors
    If (Not errors.PISystemErrors Is Nothing AndAlso errors.PISystemErrors.Count > 0) Then
        For Each item As KeyValuePair(Of PISystem, Exception) In errors.PISystemErrors
            Console.WriteLine("  AFValue '{0}': {1}", item.Key, item.Value)
        Next
    End If


End If

' Get the Updated Current Values for the Attributes
currentValues = attrList.GetValue(newTime)
Console.WriteLine("Updated Current Values:")
For Each value As AFValue In currentValues
    Console.WriteLine("  {0}: '{1} {2}' at '{3}'", value.Attribute, value.Value, value.UOM, value.Timestamp)
Next

No code example is currently available or this language may not be supported.

No code example is currently available or this language may not be supported.

Version Information

AFSDK


See Also

In This Topic
TitleResults for “How to create a CRG?”Also Available in