AFAttribute.SetValue Method (Object, UOM)
- 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( Object newValue, UOM specifiedUOM )
Public Sub SetValue ( newValue As Object, specifiedUOM As UOM ) Dim instance As AFAttribute Dim newValue As Object Dim specifiedUOM As UOM instance.SetValue(newValue, specifiedUOM)
public: void SetValue( Object^ newValue, UOM^ specifiedUOM )
member SetValue : newValue : Object * specifiedUOM : UOM -> unit
Parameters
- newValue
- Type: SystemObject
The new value for the attribute. If the specified value is DBNull.Value, then the attribute's value will be reset back to using the default value from the Template if the template is defined or to the default value for its Type if the template is not defined. - specifiedUOM
- Type: OSIsoft.AF.UnitsOfMeasureUOM
The unit of measure of the newValue parameter. If , then the unit of measure may be specified as part of the value in string format (e.g. "100.0 ft"). Otherwise, the unit of measure of the value is assumed to be in terms of the attribute's DefaultUOM property.
Exceptions
| Exception | Condition |
|---|---|
| InvalidCastException | Thrown when the conversion from the specified UOM or to the configured Type cannot be performed. |
Remarks
This is the method used to set an attribute's value. The current time is used as the default timestamp. Since the value is being set, the AFValue.IsGood flag is set to .
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. |