FieldRef on Field Name and not Field No.?

NavJen
NavJen Member Posts: 14
I am trying to modify the value of a field that is in multiple tables. The field has the same name in the multiple tables but a different field no. in each table.

I have created a table that has a list of table nos. I've written a codeunit that creates a RecordRef to each table. I know that I can create a FieldRef to a particular field in the table by using FieldReference = TableReference.FIELD("Field No."). However, I know the Field Name and not the Field No.

I know that I could use TableReference.FIELDINDEX to loop through each field in the table and compare the Name to the name that I want, but it seems like there should be an easier/better way. Any suggestions?

Thanks!

Answers

  • kriki
    kriki Member, Moderator Posts: 9,132
    You can use the table Field to search for your field.
    recField.RESET;
    recField.SETCURRENTKEY("Table No.","No.");
    recField.SETRANGE("Table No.",rerRecordReference.ID); // I think the table no. is ID
    recField.SETRANGE("Field Name",'Your Field');
    recField.FINDFIRST;
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • NavJen
    NavJen Member Posts: 14
    Thanks! I knew there had to be some easy way I was overlooking.