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

AF SDK Reference

AFDataReference.UpdateValues Method (AFValues, AFUpdateOption, AFBufferOption)

AFDataReference.UpdateValues Method (AFValues, AFUpdateOption, AFBufferOption)

  • Last UpdatedNov 18, 2025
  • 8 minute read
AFDataReference.UpdateValues Method (AFValues, AFUpdateOption, AFBufferOption)
This method writes or replaces one or more values on the target system using the configured data reference.

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

Syntax

public virtual AFErrors<AFValue> UpdateValues(
	AFValues values,
	AFUpdateOption updateOption,
	AFBufferOption bufferOption
)
Public Overridable Function UpdateValues ( 
	values As AFValues,
	updateOption As AFUpdateOption,
	bufferOption As AFBufferOption
) As AFErrors(Of AFValue)

Dim instance As AFDataReference
Dim values As AFValues
Dim updateOption As AFUpdateOption
Dim bufferOption As AFBufferOption
Dim returnValue As AFErrors(Of AFValue)

returnValue = instance.UpdateValues(values, 
	updateOption, bufferOption)
public:
virtual AFErrors<AFValue^>^ UpdateValues(
	AFValues^ values, 
	AFUpdateOption updateOption, 
	AFBufferOption bufferOption
)
abstract UpdateValues : 
        values : AFValues * 
        updateOption : AFUpdateOption * 
        bufferOption : AFBufferOption -> AFErrors<AFValue> 
override UpdateValues : 
        values : AFValues * 
        updateOption : AFUpdateOption * 
        bufferOption : AFBufferOption -> AFErrors<AFValue> 

Parameters

values
Type: OSIsoft.AF.AssetAFValues
The values to be written or replaced on the target system.
updateOption
Type: OSIsoft.AF.DataAFUpdateOption
An enumeration value that specifies how duplicate values should be handled.
bufferOption
Type: OSIsoft.AF.DataAFBufferOption
An enumeration value that specifies buffering option.

Return Value

Type: AFErrorsAFValue
If there are no errors, then is returned. Otherwise an AFErrorsTKey instance containing error information is returned.

Exceptions

ExceptionCondition
ArgumentNullException The values is .
ArgumentException The values must contain at least one AFValue.
InvalidOperationException The Attribute does not have a data reference configured.
NotSupportedException The data reference does not support this method.

Remarks

This method requires that the attributes being written, if configured with a data reference, must support the UpdateValues method. This is indicated by having the UpdateValues flag set in the SupportedDataMethods property. The PI Point Data Reference supports UpdateValues for simply configured PI Points.

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 AFBufferOption is set to Buffer, this method requires that the attribute has a configured data reference which supports buffering. This is indicated by having the Buffering flag set in the SupportedDataMethods property. The PI Point Data Reference supports buffering.

Note Notes to Callers
This method, property, or class is not available in the legacy .NET 3.5 version of the SDK.

Security note Security Note
You must have WriteData security rights to write a data value.

Important note Important
This method is not supported for attributes that do not have a data reference. Consider using AFListData.UpdateValues.

Examples

// This example demonstrates how to update values to an attribute with PIPoint data reference.
// Note: For successful write through Buffer, PI Buffer Subsystem needs to be correctly pre-configured with PI Buffer Manager. 

// Get the Database and UOMs
PISystems myPISystems = new PISystems();
PISystem myPISystem = myPISystems.DefaultPISystem;
AFDatabase myDB = myPISystem.Databases.DefaultDatabase;
UOM uomFoot = myPISystem.UOMDatabase.UOMs["foot"];
UOM uomYard = myPISystem.UOMDatabase.UOMs["yard"];

// Create an Attribute and its new values
AFAttribute myAttribute = null;
AFTime newStartTime = new AFTime("T-1d", CultureInfo.CurrentCulture);
AFValues newValues = new AFValues();
Random randomValues = new Random();

// Create Dynamic Attribute to a PIPoint to Update
PIServer piServer = PIServers.GetPIServers().DefaultPIServer;
int dataCount = 5; //Create 5 new values to update
AFTime newTime = newStartTime;
PIPoint point;
if (!PIPoint.TryFindPIPoint(piServer, "MyTestPoint#1", out point))
{
    point = piServer.CreatePIPoint("MyTestPoint#1");
}
myAttribute = new AFAttribute(String.Format(CultureInfo.InvariantCulture, @"\\{0}\{1}", piServer.Name, point.Name));
myAttribute.DefaultUOM = uomFoot;
myAttribute.ConfigString += ";ReadOnly=False";
for (int i = 0; i < dataCount; i++)
{
    AFValue newValue = new AFValue(myAttribute, randomValues.NextDouble(), newTime, uomYard);
    newValues.Add(newValue);
    newTime = newTime.LocalTime.AddMinutes(10);
}
AFTime newEndTime = newTime;

// Get the Recorded Values for the Attribute
AFValues recordedValues = myAttribute.Data.RecordedValues(new AFTimeRange(newStartTime, newEndTime), AFBoundaryType.Inside,
    myAttribute.DefaultUOM, null, false);
Console.WriteLine("Recorded Values:");
foreach (AFValue value in recordedValues)
{
    Console.WriteLine("  {0}: '{1} {2}' at '{3}'",
        value.Attribute, value.Value, value.UOM, value.Timestamp);
}

// Get the Buffer Option
// Note: If not specified in AFSDK.config, the buffer option is defaulted to "BufferIfPossible". 
Console.WriteLine("Current Buffer Option: {0}", AFData.BufferOption);

// Set the Buffer Option to "Buffer" if it is not already, which will be valid throughout this client instance.
if (AFData.BufferOption != AFBufferOption.Buffer)
{
    AFData.BufferOption = AFBufferOption.Buffer;
    Console.WriteLine("Current Buffer Option for this instance has been changed to: {0}", AFData.BufferOption);
}

//1. Update the Attribute Values and Display any Errors
AFErrors<AFValue> errorsWithBuffer =
    myAttribute.Data.UpdateValues(newValues, AFUpdateOption.InsertNoCompression); //Insert or InsertNoCompression
Thread.Sleep(1000);

if (errorsWithBuffer != null && errorsWithBuffer.HasErrors)
{
    Console.WriteLine("\nErrors returned from AFAttribute.Data.UpdateValues:");

    // Display Value errors
    if (errorsWithBuffer.Errors != null && errorsWithBuffer.Errors.Count > 0)
    {
        foreach (var item in errorsWithBuffer.Errors)
        {
            Console.WriteLine("  AFValue '{0}': {1}", item.Key, item.Value);
        }
    }

    // Display error from the PI Data Archive
    if (errorsWithBuffer.PIServerErrors != null && errorsWithBuffer.PIServerErrors.Count > 0)
    {
        foreach (var item in errorsWithBuffer.PIServerErrors)
        {
            Console.WriteLine("  AFValue '{0}': {1}", item.Key, item.Value);
        }
    }

    // Display PI System errors
    if (errorsWithBuffer.PISystemErrors != null && errorsWithBuffer.PISystemErrors.Count > 0)
    {
        foreach (var item in errorsWithBuffer.PISystemErrors)
        {
            Console.WriteLine("  AFValue '{0}': {1}", item.Key, item.Value);
        }
    }
}


//2. Alternatively, one can specify buffer option in the UpdateValues method
AFErrors<AFValue> errorsWithBufferIfPossible =
    myAttribute.Data.UpdateValues(newValues, AFUpdateOption.InsertNoCompression, AFBufferOption.BufferIfPossible);
Thread.Sleep(1000);

// Get the Updated Recorded Values for the Attributes
AFValues recordedValuesUpdated = myAttribute.Data.RecordedValues(new AFTimeRange(newStartTime, newEndTime), AFBoundaryType.Inside,
    myAttribute.DefaultUOM, null, false);
Console.WriteLine("\nUpdated Recorded Values:");
foreach (AFValue value in recordedValuesUpdated)
{
    Console.WriteLine("  {0}: '{1} {2}' at '{3}'",
        value.Attribute, value.Value, value.UOM, value.Timestamp);
}
' This example demonstrates how to update values to an attribute with PIPoint data reference.
' Note: For successul write through Buffer, PI Buffer Subsystem needs to be correctly pre-configured with PI Buffer Manager. 

' 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 uomFoot As UOM = myPISystem.UOMDatabase.UOMs("foot")
Dim uomYard As UOM = myPISystem.UOMDatabase.UOMs("yard")

' Create an Attribute and its new values
Dim myAttribute As AFAttribute = Nothing
Dim newStartTime As AFTime = New AFTime("T-1d", CultureInfo.CurrentCulture)
Dim newValues As AFValues = New AFValues
Dim randomValues As Random = New Random()

' Create Dynamic Attribute to a PIPoint to Update
Dim piServer As PIServer = PIServers.GetPIServers.DefaultPIServer
Dim dataCount As Integer = 5 'Create 5 new values to update
Dim newTime As AFTime = newStartTime
Dim point As PIPoint = Nothing
If Not PIPoint.TryFindPIPoint(piServer, "MyTestPoint#1", point) Then
    point = piServer.CreatePIPoint("MyTestPoint#1")
End If
myAttribute = New AFAttribute(String.Format(CultureInfo.InvariantCulture, "\\{0}\{1}", piServer.Name, point.Name))
myAttribute.DefaultUOM = uomFoot
myAttribute.ConfigString = (myAttribute.ConfigString + ";ReadOnly=False")
For i As Integer = 1 To dataCount
    Dim newValue As AFValue = New AFValue(myAttribute, randomValues.NextDouble(), newTime, uomYard)
    newValues.Add(newValue)
    newTime = newTime.LocalTime.AddMinutes(10)
Next
Dim newEndTime As AFTime = newTime

' Get the Recorded Values for the Attribute
Dim recordedValues As AFValues = myAttribute.Data.RecordedValues(New AFTimeRange(newStartTime, newEndTime), AFBoundaryType.Inside,
    myAttribute.DefaultUOM, Nothing, False)
Console.WriteLine("Recorded Values:")
For Each value As AFValue In recordedValues
    Console.WriteLine("  {0}: '{1} {2}' at '{3}'",
        value.Attribute, value.Value, value.UOM, value.Timestamp)
Next

' Get the Buffer Option
' Note: If not specified in AFSDK.config, the buffer option is defaulted to "BufferIfPossible". 
Console.WriteLine("Current Buffer Option: {0}", AFData.BufferOption)

' Set the Buffer Option to "Buffer" if it is not already, which will be valid throughout this client instance.
If Not AFData.BufferOption.Equals(AFBufferOption.Buffer) Then
    AFData.BufferOption = AFBufferOption.Buffer
    Console.WriteLine("Current Buffer Option for this instance has been changed to: {0}", AFData.BufferOption)
End If

'1. Update the Attribute Values and Display any Errors
Dim errorsWithBuffer As AFErrors(Of AFValue) =
    myAttribute.Data.UpdateValues(newValues, AFUpdateOption.InsertNoCompression) 'Insert or InsertNoCompression
Thread.Sleep(1000)

If Not errorsWithBuffer Is Nothing AndAlso errorsWithBuffer.HasErrors Then
    Console.WriteLine("Errors returned from AFAttribute.Data.UpdateValues:")

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

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

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


'2. Alternatively, one can specify buffer option in the UpdateValues method
Dim errorsWithBufferIfPossible As AFErrors(Of AFValue) =
    myAttribute.Data.UpdateValues(newValues, AFUpdateOption.InsertNoCompression, AFBufferOption.BufferIfPossible)
Thread.Sleep(1000)

' Get the Updated Recorded Values for the Attributes
Dim recordedValuesUpdated As AFValues = myAttribute.Data.RecordedValues(New AFTimeRange(newStartTime, newEndTime), AFBoundaryType.Inside,
    myAttribute.DefaultUOM, Nothing, False)
Console.WriteLine("Updated Recorded Values:")
For Each value As AFValue In recordedValuesUpdated
    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

Supported in: 3.1.1, 3.1.0, 3.0.2, 3.0.1, 3.0.0, 2.10.11, 2.10.5, 2.10.0, 2.10, 2.9.5, 2.9, 2.8.5, 2.8, 2.7.5, 2.7, 2.6

See Also

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