Empty field values for several fields

Crunch
Member Posts: 38
Very new at this, so excuse the perhaps easy question.
I have a range of fields from field x to field y, that I would like to "empty" in all records by setting them to either 0 or '' with modifyall in a switch case depending on their datatype.
I'm unsure how to iterate through just the fields from x to y.
I have a range of fields from field x to field y, that I would like to "empty" in all records by setting them to either 0 or '' with modifyall in a switch case depending on their datatype.
I'm unsure how to iterate through just the fields from x to y.
0
Comments
-
Read up about Recordrefs and Fieldrefs in the helpfile, that'll give you what you need.0
-
How about a processing report on the table that has these fields.
OnAfterGetRecord()
CLEAR(Fieldx)
CLEAR(Fieldy)
Modify;
You're trying to clear out certain fields? Or all fields?0 -
I had a way of doing it with recordrefs, but then realized, that they are not available in 2.50.
Sorry, but I posted in the wrong section of the forum. Hopefully a mod can move it.
Been trying to work it out with either Field or Object, but can't seem to get Modifyall working in regards to the fieldname. It needs a record.WITH Field DO BEGIN SETRANGE("No.",6000000,6009999); IF FIND('-') THEN REPEAT Object.SETRANGE(Type,Object.Type::Table); Object.SETRANGE(ID,TableNo); IF Object.FIND('-') THEN CASE Type OF Type::Integer: Object.MODIFYALL(Field.FieldName,0); Type::Boolean: Object.MODIFYALL(Field.FieldName,FALSE); Type::Option: Object.MODIFYALL(Field.FieldName,0); Type::Text: Object.MODIFYALL(Field.FieldName,''); Type::Date: Object.MODIFYALL(Field.FieldName,0D); Type::Decimal: Object.MODIFYALL(Field.FieldName,0); Type::Code: Object.MODIFYALL(Field.FieldName,''); END; UNTIL NEXT = 0; END;
0 -
Hi Crunch,
If you are looking for updating blank and zero values dynamically on a table (on a range of fields, starting from x to y) the following code can help. (I am considering the field id range from 50000 to 50002)
// First create 3 fields in the Vendor (23) Table like:
// ID Name Type Length
// 50000 Dec Decimal
// 50001 Txt Text 30
// 50002 Cod Code 10
Create a new report, take Vendor table (23) as a dataitem and put the following code in OnAfterGetRecord trigger.
// Variables used:
// Name Type Length
// TbRecRef RecordFef
// TbFieldRef FieldRef
// PString text 30
// TbFieldName text 30
// TbDataType text 30
CLEAR(TbRecRef);
TbRecRef.OPEN(23); // Vendor Table
TbRecRef.GETTABLE(Vendor);
PString := Vendor.GETPOSITION();
TbRecRef.SETPOSITION(PString);
FOR i := 50000 TO 50002 DO BEGIN
TbFieldRef := TbRecRef.FIELD(i);
TbFieldName := TbFieldRef.NAME;
TbDataType := FORMAT(TbFieldRef.TYPE);
CASE TbDataType OF
'Code', 'Text': TbFieldRef.VALUE := '';
'Integer': TbFieldRef.VALUE := 0;
'Decimal': TbFieldRef.VALUE := 0;
END;
END;
TbRecRef.MODIFY;
TbRecRef.CLOSE;
Before running the report, put some values in the fields, Dec, Cod and Txt so that you can check the execution.
Hope this helps.
Chn0 -
Thank you all for your input and help, but for the moment we have resigned to typing it manually seeing as we can't use Recrefs.
Best Regards.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