AFAttribute.SetValue Method (AFValue)
- Last UpdatedNov 18, 2025
- 4 minute read
- PI System
- AF SDK 2024 R2
- Developer
Namespace: OSIsoft.AF.Asset
Assembly: OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.1.1.1182
Syntax
public void SetValue( AFValue newValue )
Public Sub SetValue ( newValue As AFValue ) Dim instance As AFAttribute Dim newValue As AFValue instance.SetValue(newValue)
public: void SetValue( AFValue^ newValue )
member SetValue : newValue : AFValue -> unit
Parameters
- newValue
- Type: OSIsoft.AF.AssetAFValue
The new AFValue object for the attribute's value. If the AFValue.Value is DBNull.Value, then the attribute's value will be reset back to using the default value from the template. A value of DBNull.Value is not allowed if the attribute does not have a Template defined. Proper UOM coercion of Value will be performed in terms of the attribute's DefaultUOM property. If the data reference is a PI Point then proper type coercion of Value will be performed in terms of the PointType property.
Exceptions
Remarks
This is the method used to set an attribute's value when using an AFValue object. It allows all of the properties of the AFValue to be set before writing the value. The value will be written at the time specified by the AFValue.Timestamp property.
The data reference configuration specifies how to write the value of the attribute. The AFDataReference.UOM property specifies the actual UOM of the external data value referenced by this attribute. The AFValue.UOM property specifies the unit of measure of the value passed to this method. Before writing the value to the external data store, if value's status is good, then the value is converted to the unit of measure specified by the configured AFDataReference.UOM property. If the value's status is good and the Type for this attribute other than Object, then the value will be converted to that type after the unit-of-measure conversion before being sent to the data reference's SetValue(Object, AFValue) method.
A value of any type may be written with SetValue, however, in order for a value to be saved, it must either be a .NET base type, a .NET serializable type, or support the PI SDK's IPIPersist interface. This means it is possible to write values such as Array, DataSet, PISDK.PIPoint, and references to other AF SDK objects. All DataReferences are not required to support all .NET types so the value must be compatible with the underlying AFDataReference configured for the attribute.
The AF SDK will process arrays for unit-of-measure and type conversion by the same mechanism described above on each item of the array.
If a failure occurs during an attempt to write to a data reference, the error is logged to the user but any previous write operations are not undone.
If the data reference is a PI Point then this call is equivalent to UpdateValue Overload with AFUpdateOption set to Replace
If the attribute does not have a data reference configured and if it is not a dynamic attribute, then the attribute's value will be updated in the PI AF Server immediately. Updating a value to a PI AF Server Collective requires the primary AF Server to be running and will be replicated to the secondary AF Server through SQL Server replication.
If multiple attributes of this type are written to, consider using the AFListData.UpdateValues method for better performance.
If the AFAttribute.IsConfigurationItem is set for the attribute, setting the attribute value is treated as a configuration change to the owning element or event frame, and will cause a check out. Write permission is required for setting the value and a check-in is required for non-data reference attribute values to be saved back to the PI AF Server.
If AFAttribute.IsConfigurationItem is not set for the attribute, the WriteData permission is required for setting the value and a check out of the owning object will not occur.
| You must have WriteData security rights to write a non-configuration attribute value. |