Hi,
I'm trying to use a FieldRef to change a value of some field of some record.
First I am writing the new value to my FieldRef using the EVALUATE function. Then I run the VALIDATE function to make sure my code in the OnValidate-Trigger will also run.
So far this works, but now I have the problem that inside the OnValidate trigger my xRec already holds the new value instad of the old. So a condition like Rec.Description <> xRec.Description will not work.
Any ideas how to handle this?
I need the EVALUATE, because I do not know what type the value is. But I also need the OnValidate trigger to be fired correctly (with xRec containing the old value and Rec containing the new).
EVALUATE(FieldRef,XmlNode.InnerText,9);
FieldRef.VALIDATE;
Answers
But I am not satisfied. It seems to be more complicated than neccessary. But right now I couldn't come up with something better.
I am surprised your code should work. With your EVALUATE statement, NAV should actually try to construct a value of type FieldRef from your data. I thought this definitely had to be EVALUATE(FieldRef.VALUE, ... But maybe C/AL starts to exhibit some c#-behavior.
If the type of FIELD(FieldID) is always the same, I suggest you declare a variable of that type to replace FieldRef2.
If this is not the case, you can declare variables of each possible type and then do CASE FORMAT(FielldRef.TYPE) of ...
So, if your type is generic, there is no simple (short) way to do it. EVALUATE needed to return the value, rather than success state.
I thought about the possibility to create a variable for each type, but since every type is possible this would be a much bigger case statement than my code above. I'll probably just have to go with that.
Thank you again for your feedback, vaprog.