"IF Validate" Function

Belias
Member Posts: 2,998
with this codeunit, you can manage the possible validate errors (like overflow etc).
Here's an example on how to use this codeunit:

*edit:
a possible use of this codeuint is when you are batch processing something: you can use getlasterrortext function to create a simple log if the validate goes error...
Enjoy!
OBJECT Codeunit 90000 If Validate Mgt { OBJECT-PROPERTIES { Date=09/02/09; Time=12.23.59; Modified=Yes; Version List=; } PROPERTIES { OnRun=BEGIN FNTValidate; END; } CODE { VAR INTFieldNo@1101339002 : Integer; TXTNewValue@1101339001 : Text[250]; FRFieldRef@1101339004 : FieldRef; RRRecordRef@1101339000 : RecordRef; PROCEDURE FNTValidate@1101339001(); BEGIN IF TXTNewValue = '' THEN BEGIN FRFieldRef.VALIDATE; END ELSE BEGIN EVALUATE(FRFieldRef,TXTNewValue); FRFieldRef.VALIDATE; END; END; PROCEDURE FNTGetPar@1101339003(INTLocTableNo@1101339000 : Integer;INTLocFieldNo@1101339001 : Integer;TXTLocPosition@1101339002 : Text[1000];TXTLocValue@1101339003 : Text[250]); BEGIN TXTNewValue := TXTLocValue; RRRecordRef.OPEN(INTLocTableNo); RRRecordRef.SETPOSITION(TXTLocPosition); RRRecordRef.FIND('='); FRFieldRef := RRRecordRef.FIELD(INTLocFieldNo); END; PROCEDURE FNTGetTableNo@1101339000(TXTTableName@1101339001 : Text[50]) : Integer; VAR TBObject@1101339000 : Record 2000000001; BEGIN TBObject.SETRANGE(Type,TBObject.Type::Table); TBObject.SETRANGE(Name,TXTTableName); TBObject.FINDFIRST; EXIT(TBObject.ID); END; BEGIN END. } }
Here's an example on how to use this codeunit:
OBJECT Codeunit 66666 getpos { OBJECT-PROPERTIES { Date=09/02/09; Time=12.27.22; Modified=Yes; Version List=; } PROPERTIES { OnRun=BEGIN txtconst := 'mlallalllllflljfdshalfjadskfljadslfkjadslfjhadslfjhadsfhsadlkfhdslafhekhfuniciabernciebhrigvbiero'; tbtest.FINDLAST; cu.FNTGetPar(cu.FNTGetTableNo(tbtest.TABLENAME),tbtest.FIELDNO(Name),tbtest.GETPOSITION(FALSE),txtconst); IF cu.RUN THEN BEGIN tbtest.VALIDATE(Name,txtconst); tbtest.MODIFY; END ELSE BEGIN MESSAGE('What customer is this?'); END; END; } CODE { VAR tbtest@1101339000 : Record 18; rref@1101339001 : RecordRef; cu@1101339002 : Codeunit 90000; txtconst@1101339003 : Text[200]; BEGIN END. } }Maybe there are problems with transactions, codeunit.run and "complex" validates...not tried yet...for sure, you should know what you are validating before using this function.

*edit:
a possible use of this codeuint is when you are batch processing something: you can use getlasterrortext function to create a simple log if the validate goes error...
Enjoy!
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