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

AF SDK Reference

AFAttribute.SetValue Method (AFCase, AFValue)

  • Last UpdatedNov 18, 2025
  • 4 minute read
AFAttribute.SetValue Method (AFCase, AFValue)
This method sets the value for an attribute into the result set of the specified caseContext using the specified AFValue object. Values written into the case can be subsequently output to associated data references by invoking AFCase.Publish method.

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

Syntax

public void SetValue(
	AFCase caseContext,
	AFValue newValue
)
Public Sub SetValue ( 
	caseContext As AFCase,
	newValue As AFValue
)

Dim instance As AFAttribute
Dim caseContext As AFCase
Dim newValue As AFValue

instance.SetValue(caseContext, newValue)
public:
void SetValue(
	AFCase^ caseContext, 
	AFValue^ newValue
)
member SetValue : 
        caseContext : AFCase * 
        newValue : AFValue -> unit 

Parameters

caseContext
Type: OSIsoft.AF.AnalysisAFCase
The case context to be used when setting the attribute's value. The value will added to the case's result set as an output. Invoking AFCase.Publish will write all result set outputs to the data references which support it. If the case context is null, this method will perform the same as SetValue(AFValue).
newValue
Type: OSIsoft.AF.AssetAFValue
The new AFValue for the attribute. If the specified AFValue.Value is DBNull.Value and the caseContext is , 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. A value of DBNull.Value is not allowed if the caseContext is specified.

Exceptions

ExceptionCondition
InvalidCastException Thrown when the conversion to the configured Type cannot be performed.

Remarks

This method sets the value for an attribute into the result set of the specified caseContext using the specified AFValue object. Values written into the case can be subsequently output to associated data references by invoking AFCase.Publish method. 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 case context in effect for the method call is not , then the value will be added to the result set of the AFCase. Subsequent calls to GetValue with the same case context will not invoke the data reference but return the stored result value. If the IsConfigurationItem is , then the attribute's value cannot be set within a case context.

If the Element associated with this attribute has more than one AFVersion associated with it and a QueryDate for the element has not been specified, then this method will invoke the call on the version of the element corresponding to the specified context.

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.

Security note Security Note
You must have WriteData security rights to write a non-configuration attribute value.

Version Information

AFSDK


See Also

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