Record Ref and Field Ref - Dynamic

VSubaVSuba Member Posts: 28
Hi Experts,

In a record variable, how can i check for Field no. that exist in the Record Variable or not... Dynamically i want to pass the Field Name to the Record Variable say.. Customer No. and get the Field No. from that Customer table.

When i pass the variable like this...
E.g.
FName := 'Name';
FieldNo := Customer.FieldName(FName);

It says error...i might be wrong.. but i don't know how to give the syntax for this...i need to pass parameters as a text variable(of Field Name) dynamically...and fetch the Field No. from Customer Table...
Any one has any idea about this....please...

Thanks...
Thanks & Regards...
Suba

Comments

  • BourgeoisBourgeois Member Posts: 5
    You could query the "Field" table [2000000041] or check every 'FieldRef' found for your record reference.
  • BeliasBelias Member Posts: 2,998
    I would go for the field table method, as Bourgeois said
    anyway, FIELDNAME function doesn't work like this
    FName := 'Name';
    FieldNo := Customer.FieldName(FName);
    
    read the online help. This function is useless for your purpose :roll:
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • VSubaVSuba Member Posts: 28
    Hi,

    I have used the Field table only for values from a Field Name... My query is whether dynamically get the field no. when i pass the field Name as a string....??

    Thanks...
    Thanks & Regards...
    Suba
  • BeliasBelias Member Posts: 2,998
    AFAIK, this function does not exist. you have to pass the field (not the field name as a string) in order to get its number.
    if you just have the field name as a string, you have to filter the table for table no. and field name, then do a findfirst and you got the field no.
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • VSubaVSuba Member Posts: 28
    I got the Field Name...Say for E.g.Text = Name, So from Field Table i can get the field No. as 2 of Customer Table.

    In RecordRef, my code is...

    MField.RESET;
    MField.SETCURRENTKEY(TableNo,"No.");
    MField.SETRANGE(TableNo,18);
    MField.SETRANGE("No.",2);
    IF MField.FIND('-') THEN
    REPEAT
    RecRef.OPEN(MField.TableNo);
    IF RecRef.FIND('-') THEN
    REPEAT
    FldRef := RecRef.FIELD(MField."No."); //Pass the Field Nos. to get the value
    IF Customer.Name = FORMAT(FldRef.VALUE) THEN BEGIN
    message(FORMAT(FldRef.VALUE));
    END;
    until recref.next = 0;
    RecRef.CLOSE;

    In this code, i have highlighted a place where i want to compare the text field where i have the Field Name...
    So how to compare the String which holds Field Name against the value...
    can i convert the String into an executable code???
    Thanks & Regards...
    Suba
  • BourgeoisBourgeois Member Posts: 5
    You already use part of the solution for one field, why not do the same logic twice?

    Here's an example of how you could create a '''dynamic''' match finder by using just
    the Table-ID and two field names as parameters.

    Be aware that this code is without checks on the returned Field-ID. You could easily add some code to check
    the returned field id first.
    OnRun=VAR
       lintTableID@1100095000 : Integer;
       BEGIN
         FindMatch(18,'Name','Address');
       END;
      }
      CODE
      {
        PROCEDURE FindMatch@1100095001(pintTableID@1100095000 : Integer;ptxtField1@1100095001 : Text[250];ptxtField2@1100095002 : Text[250]);
        VAR
          lrecRef@1100095003 : RecordRef;
          lrefField1@1100095005 : FieldRef;
          lrefField2@1100095004 : FieldRef;
        BEGIN
          lrecRef.OPEN(pintTableID);
          IF lrecRef.FIND('-') THEN REPEAT
            lrefField1 := lrecRef.FIELD(GetFieldNo(pintTableID,ptxtField1));
            lrefField2 := lrecRef.FIELD(GetFieldNo(pintTableID,ptxtField2));
    
            IF (FORMAT(lrefField1.VALUE) = FORMAT(lrefField2.VALUE)) THEN
              MESSAGE(FORMAT(lrefField1.VALUE));
    
          UNTIL lrecRef.NEXT = 0;
          lrecRef.CLOSE;
        END;
    
        PROCEDURE GetFieldNo@1100095000(pintTableID@1100095000 : Integer;ptxtFieldName@1100095001 : Text[250]) FieldNo : Integer;
        VAR
          lrec_Field@1100095002 : Record 2000000041;
        BEGIN
          CLEAR(lrec_Field);
          lrec_Field.SETCURRENTKEY(TableNo,"No.");
          lrec_Field.SETRANGE(TableNo, pintTableID);
          lrec_Field.SETRANGE(FieldName,ptxtFieldName);
          IF NOT lrec_Field.FINDFIRST THEN
            EXIT(0);
    
          EXIT(lrec_Field."No.");
        END;
    

    Regards, Bart
Sign In or Register to comment.