FieldRef.VALIDATE (Rec & xRec)

naff
Member Posts: 32
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).
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;
0
Best Answer
-
Hi naff,
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.5
Answers
-
Ok, I think I found a solution.
But I am not satisfied. It seems to be more complicated than neccessary. But right now I couldn't come up with something better.FieldRef := RecRef.FIELD(FieldID); RecRef2 := RecRef.DUPLICATE; FieldRef2 := RecRef2.FIELD(FieldID); EVALUATE(FieldRef2,XmlNode.InnerText,9); FieldRef.VALIDATE(FieldRef2.VALUE);
1 -
Hi naff,
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.5 -
EVALUATE(FiedRef.VALUE,...) doesn't compile.
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.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions