How to evaluate a value into a FieldRef?

Timo_Lässer
Member Posts: 481
I tried to evaluate a field from a record into a FieldRef.
I use 3.70 (HF12) client and get following error message:
EVALUATE(|Fldref.Value,Record.Field);
Can anybody tell me how to evaluate a value into a FieldRef?
I use 3.70 (HF12) client and get following error message:
The cursor is set toA variable was expected. For example:
MyVar
Customer.Name
EVALUATE(|Fldref.Value,Record.Field);
Can anybody tell me how to evaluate a value into a FieldRef?
Timo Lässer
Microsoft Dynamics NAV Developer since 1997
MSDynamics.de - German Microsoft Dynamics Community - member of [clip]
Microsoft Dynamics NAV Developer since 1997
MSDynamics.de - German Microsoft Dynamics Community - member of [clip]
0
Comments
-
This is how I chose to do it:
CASE FORMAT(FR.TYPE) OF 'Text': BEGIN EVALUATE(txtDummy,"Some Text"); IF "booUseValidate" THEN FR.VALIDATE(locText) ELSE FR.VALUE(locText); END;
0 -
That's seems to be the only way to do itTimo Lässer
Microsoft Dynamics NAV Developer since 1997
MSDynamics.de - German Microsoft Dynamics Community - member of [clip]0 -
Why so sad?"Real programmers don't comment their code.
If it was hard to write, it should be hard to understand."0 -
I have written a Codeunit which evaluates a Text into a FieldRef.
In this Codeunit I have listet all possible data types (except for BLOB because this is not availible for a variable) in a CASE structure.
This would be needless if the EVALUATE could handle FieldRef.Timo Lässer
Microsoft Dynamics NAV Developer since 1997
MSDynamics.de - German Microsoft Dynamics Community - member of [clip]0 -
True, but not possible.
Some information isn't know on the recref level. So you will always need to get the fldref first."Real programmers don't comment their code.
If it was hard to write, it should be hard to understand."0 -
eromein wrote:Some information isn't know on the recref level. So you will always need to get the fldref first.
I wanted to evaluate into a FieldRef:Timo Lässer wrote:EVALUATE(Fldref.Value,Record.Field);
So I wrote this function(s):Global Text000 = '%1' is not a valid %2 value. EvaluateFieldRef(VAR ToFieldRef : FieldRef;FromText : Text[250];HideDialog : Boolean) : Boolean // // Evaluates a text into a FieldRef variable // CASE UPPERCASE(FORMAT(ToFieldRef.TYPE)) OF 'INTEGER': IF EVALUATE(DummyInteger,FromText) THEN BEGIN ToFieldRef.VALUE := DummyInteger; EXIT(TRUE); END; 'TEXT','TABLEFILTER': BEGIN ToFieldRef.VALUE := COPYSTR(FromText,1,ToFieldRef.LENGTH); EXIT(TRUE); END; 'CODE': BEGIN ToFieldRef.VALUE := UPPERCASE(COPYSTR(FromText,1,ToFieldRef.LENGTH)); EXIT(TRUE); END; 'DECIMAL': IF EVALUATE(DummyDecimal,FromText) THEN BEGIN ToFieldRef.VALUE := DummyDecimal; EXIT(TRUE); END; 'OPTION': IF STRPOS(UPPERCASE(FldRef.OPTIONCAPTION),UPPERCASE(FromText)) > 0 THEN BEGIN IF FldRef.OPTIONCAPTION[1] = ',' THEN I := 2 ELSE I := 1; WHILE STRPOS(UPPERCASE(SELECTSTR(I,FldRef.OPTIONCAPTION)),UPPERCASE(FromText)) = 0 DO I += 1; ToFieldRef.VALUE := SELECTSTR(I,FldRef.OPTIONCAPTION); EXIT(TRUE); END; 'BOOLEAN': IF EVALUATE(DummyBoolean,FromText) THEN BEGIN ToFieldRef.VALUE := DummyBoolean; EXIT(TRUE); END; 'DATE': BEGIN AppMgt.MakeDateText(FromText); IF EVALUATE(DummyDate,FromText) THEN BEGIN ToFieldRef.VALUE := DummyDate; EXIT(TRUE); END; END; 'TIME': IF EVALUATE(DummyTime,FromText) THEN BEGIN ToFieldRef.VALUE := DummyTime; EXIT(TRUE); END; 'DATETIME': IF EVALUATE(DummyDateTime,FromText) THEN BEGIN ToFieldRef.VALUE := DummyDateTime; EXIT(TRUE); END; 'BINARY': IF EVALUATE(DummyBinary,FromText) THEN BEGIN ToFieldRef.VALUE := DummyBinary; EXIT(TRUE); END; // 'BLOB':; // Not allowed 'DATEFORMULA': IF EVALUATE(DummyDateFormula,FromText) THEN BEGIN ToFieldRef.VALUE := DummyDateFormula; EXIT(TRUE); END; 'BIGINTEGER': IF EVALUATE(DummyBigInteger,FromText) THEN BEGIN ToFieldRef.VALUE := DummyBigInteger; EXIT(TRUE); END; 'DURATION': IF EVALUATE(DummyDuration,FromText) THEN BEGIN ToFieldRef.VALUE := DummyDuration; EXIT(TRUE); END; 'GUID': IF EVALUATE(DummyGUID,FromText) THEN BEGIN ToFieldRef.VALUE := DummyGUID; EXIT(TRUE); END; 'RECORDID': IF EVALUATE(DummyRecordID,FromText) THEN BEGIN ToFieldRef.VALUE := DummyRecordID; EXIT(TRUE); END; END; IF GUIALLOWED AND NOT HideDialog THEN ERROR(Text000,FromText,FORMAT(ToFieldRef.TYPE)) ELSE BEGIN LastErrorText := STRSUBSTNO(Text000,FromText,FORMAT(ToFieldRef.TYPE)); EXIT(FALSE); END; GetLastErrorText() : Text[1024] EXIT(LastErrorText);
So you can evaluate any text into any FieldRefIF NOT EvaluateFieldRef(MyFieldRef,MyText,TRUE) THEN DoSomethingWith(GetLastErrorText);
Timo Lässer
Microsoft Dynamics NAV Developer since 1997
MSDynamics.de - German Microsoft Dynamics Community - member of [clip]2 -
I made this a long time ago. I know it is not completly correct, but it was enough for what I wanted to do.
This code takes a value and sets it to a specific format which is defined by the user and is stored in the field "FormatString".FldRef := RecRef.FIELD(Veldnummer); IF FORMAT(FldRef.CLASS) = 'FlowField' THEN FldRef.CALCFIELD; IF FormatString='' THEN EXIT(FORMAT(FldRef.VALUE)) ELSE BEGIN -> IF EVALUATE(DecimalValue, FORMAT(FldRef.VALUE) ) THEN BEGIN EXIT(FORMAT(DecimalValue,0,FormatString)) END ELSE EXIT(FORMAT(FldRef.VALUE)) END;
the line marked with the -> could be multiplied by the number of types you want to be able to handle and you could place it in a case.
I think it's about the same you have.
Could you maybe tell us what you're making here???"Real programmers don't comment their code.
If it was hard to write, it should be hard to understand."0 -
Thank you for the hint. I noticed that decimals will always be displayed without decimals if they are <> 0.eromein wrote:Could you maybe tell us what you're making here???
I have a table for importing data which is a 100% Copy of an existing table (incl. Trigger code). I've named it "<Table Name> Import Worksheet".
The User can decide which fields from the Import Worksheet should be transferred in the "real" table and what should be happen with the field values.
(Define an "Init Value" if the Import doesn't fill the field or define a "Default Value" which will overwrite the imported value.)
Furthermore the user can decide the condition when the field should be transferred (Always, If new value is <> empty, If old value is empty).
All these Setups will be made in an "Import Template" on field level.
And exactly for the "Init Value" resp. "Default Value" I need to evaluate a text into a FieldRef.Timo Lässer
Microsoft Dynamics NAV Developer since 1997
MSDynamics.de - German Microsoft Dynamics Community - member of [clip]0 -
Nice!
Is this hobby or work?"Real programmers don't comment their code.
If it was hard to write, it should be hard to understand."0 -
Timo Lässer
Microsoft Dynamics NAV Developer since 1997
MSDynamics.de - German Microsoft Dynamics Community - member of [clip]0 -
To bad, would have been a great download!"Real programmers don't comment their code.
If it was hard to write, it should be hard to understand."0 -
Timo Lässer wrote:
EvaluateFieldRef(VAR ToFieldRef : FieldRef;FromText : Text[250];HideDialog : Boolean) : Boolean
I guess this is for 3.70 and will not work in 3.60, since the fieldref.LENGTH is not available... For the rest it would work...I don't need PGP, my handwriting suffices.0 -
dennis decoene wrote:Timo Lässer wrote:
EvaluateFieldRef(VAR ToFieldRef : FieldRef;FromText : Text[250];HideDialog : Boolean) : Boolean
I guess this is for 3.70 and will not work in 3.60, since the fieldref.LENGTH is not available... For the rest it would work...
Well, use the dynamic table "Field" and find the field length.
Best regardsBest regards
Henrik Ohm0 -
Timo Lässer wrote:
// 'BLOB':; // Not allowed
Hello guys,
Anybody knows a workaround for this one? How come is it impossible to insert something into a BLOB field of RecRef?
There are also complications with reading BLOBs from RecRefs - but I can come up with a workaround at least... In case of writing into a BLOB - no idea at all
When I try to do something like this:FldRef.VALUE := MyRecord.MyBlobField;
I receive an odd message:The expression BLOB cannot be type-converted into a BLOB value.
:-kBest regards,
Dmitry0 -
i think using EVALUATE(FORMAT(fieldref.value), REcord.field) would work did you try that?Saro0
-
FldRef should be ToFieldRef?Timo_Lässer wrote: »
STRPOS(UPPERCASE(FldRef.OPTIONCAPTION),UPPERCASE(FromText)) > ..
STRPOS(UPPERCASE(SELECTSTR(I,FldRef.OPTIONCAPTION)),UPPERCASE(F..
ToFieldRef.VALUE := SELECTSTR(I,FldRef.OPTIONCAPTION);0 -
I don't know if this works in every version of NAV, but recent versions, it works if you evaluate to the FieldRef instead of the FieldRef.VALUE.
Ex.:if RecRef.FieldExists(ToFieldNo) then FldRef := RecRef.Field(ToFieldNo); if Evaluate(FldRef, MyNewValueAsText) then RecRef.Modify();
I have tested this for decimal and text fields and both work just fine.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