Starting with PI Data Archive 3.4 and above, you cannot manually set the substituted flag. This flag is set by the system during editing and cannot be directly set or cleared by the user. Only changes to the value itself are considered substitution. Please refer to KB 3030OSI8 for more information.
My advice would be grabbing the existing AFValue from your attribute, change the value property of the AFValue, and call UpdateValue with AFUpdateOption.Replace. This way, you can replace the existing value and the PI system will take care of setting the substituted flag.
Daphne pointed out very good information. From the KB:
2. The substituted flag is set only when the value actually changes. In previous releases, it was set by any editing operation, even if the value did not change or only the flags were set.
So, in case you really need to delete all values first, a workaround could be to insert two values a the same time afterwhile. I tested this and it works:
var time = AFTime.Parse("*-5m"); values.Add(new AFValue(0, time)); values.Add(new AFValue(10, time)); TagA.UpdateValues(values, AFUpdateOption.Replace);
One remark is that if your values are all the same the substituted flag will not change.
Hope this helps!
Yep, that's what I ended up doing and I also realised that an identical value will not trigger the Substituted flag.
Thanks for the help