I remember it was preferred (and about 10 times faster) to get values like this:
rather than this:
myAFCase.Elements[iIndex].Attributes[sAttribute].GetValue(youAFCase, youAFCase.TimeRange, UOM).Value;
Because the first one does consider the edits and substitutions of values, and the second one does not, and the first one is optimized, if the first one fails then you should call the second one.
Try this and let us know if it works for you :)
This was intended for AF 1.x but I'll try it in the 2.x version and tell you. This should give you an idea.
Cristobal...but retrieving a value from an AFCase has the potential to be faster than from a Data Reference. AFCase results do not invoke the Data Reference for an Attribute, they jump straight to SQL for the stored value.
Use AFAttributeList to retrieve multiple values at one time. This reduces round trips to PI to get the data. Something like:
string strAttrs = commaSepratedAttributes.Split(',');
int attrPerElement = strAttrs.Length;
AFNamedCollectionList<AFElement> elements = AFElement.FindElements(myDB, null, elementTemplate, AFSearchField.Template, true, AFSortField.Name, AFSortOrder.Ascending, 1000);
AFAttributeList alist = new AFAttributeList();
foreach (AFElement element in elements)
foreach (string strAttr in strAttrs)
if (alist.Count > 0)
StringBuilder allValues = new StringBuilder();
AFValues values = alist.GetValue();
for (int i=0; i<values.Count; i++)
AFValue val = values;
AFAttribute attr = alist;
if (i % attrPerElement > 0)
else if (i % attrPerElement == 0 && i != 0)
Note in the upcoming AF 2.1 release, there are additional examples and AFSDK methods for finding attribute values, bulk loading and retrieving attribute values.
Thanks for your reply. I am new to PI AF. I don't know how to use AFCase and i tried but not able to get sucess. It would be nice, if you can post the code....
Sorry for the late reply...
Are you reading values through a Case?