Empty field values for several fields

Crunch
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.

Comments

  • MBerger
    MBerger Member Posts: 413
    Read up about Recordrefs and Fieldrefs in the helpfile, that'll give you what you need.
  • Savatage
    Savatage Member Posts: 7,142
    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?
  • Crunch
    Crunch Member Posts: 38
    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;
    
  • Chinmoy
    Chinmoy Member Posts: 359
    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.

    Chn
  • Crunch
    Crunch Member Posts: 38
    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.