Scanning all Table fields

Is there a way for scanning all table fields values: like FOR EACH FIELDS in TABLE…? Thanks!

Ok I’ve find “Looping through the fields of a record” Post and… There is no way… Tnaks!

Hi There is no such functionality in navision for scanning each fieds using some commands like one is Visual Basic. In navision it has to be spacified the recordname and field name to get the values from a field. What functionaliy would you require by using this ? Can you explain little bit more about your objective for this ? May be some other solutions is there for the same. Regards Joseph Mathew Edited by - joseph_mathew on 2001 May 23 11:08:18

This can be done using C/Front…

I want to monitor changes on a record of X Table and write this changes (between xrec and rec) in a supervisor table. This function should be write once for all Table → … looping fields is the olny way. For now I rewrite a portion of code for each table… Bye

I don’t know if this is of any help. We had a similar problem. The limited solution we used was based around (1) using the FORMAT statement on the record to get a comma delimit strings (limitation 255 characters max). (2) iteration splitting the strings and comparing. (3) using the “2000000041 - FIELD” table to extract the name of the field changed.


Var
  FieldTable : Record 2000000041; //Field

FieldTable.Setrange(TableNo, DATABASE::Customer);
FieldTable.SETRANGE (Enabled, TRUE);
If FieldTable.Find('-') THEN REPEAT
...

UNTIL FieldTable.Next <= 0;

While you can access the Field Declaration (No, Name, Type etc.) you CANNOT access the Field Value. ------- With best regards from Switzerland Marcus Fabian

To LOG any changes I need field value… I make a function that insert a record (head)with Userid, date, time, Tablename, keyfields, and a (row) record for each field change that I want to monitor with fieldname oldvalue and newvalue. This function take a vector[50,3] as parameter for fields changes [name,oldvalue,newvalue], (50 fields to monitor is a little big…). In OnModify Trigger of XX Table I put this code … and rewrite it for each field… n:=0; //number of modifies ******************************* IF xRec.“FieldsA”<>“FieldsA” THEN BEGIN n:=n+1; vett[n,1]:=FORMAT(FIELDNAME(“FieldsA”)); vett[n,2]:=FORMAT(xRec.“FieldsA”); vett[n,3]:=FORMAT(“FieldsA”); END; ******************************** then I call my function for insert record InsertMyModify(USERID,TODAY,TIME,TABLENAME,“Nr.”,n,vett) BYE!

You will only detect changes made in the table when OnModify trigger is executed. If the table is updated in some routine, you have to update all code with MODIFY(TRUE) for the actual table. If the user makes the changes in a form, the OnModify trigger is always trigged. Then can you automatic generate a big CASE based on information In the Field table for the table and put your code in a Code unit, witch you call from the OnModify trigger. You can generate the whole Code unit with a script and import it as a text file and then compile it. If you add some new fields to the table, you just have to rerun the script.

I used the code Marcus posted for getting the fieldnames in a table into an array. I then tried to get the values from the fields by referring to a record type variable using its fieldnames dynamically. I could not accomplish that… is there a way to refer to a field when the name of that field is in a variable? MESSAGE(‘The value of field %1 is %2’,ArrFieldNames[i], varMyTable.arrFieldNames[i]); …the second parameter (%2) fails. ArrFieldNames is an array containing the fieldnames, varMyTable is a record variable and i is an integer for focusing on a field. /Pauli Edited by - paurola on 2001 May 28 11:11:01

Pauli : No you cannot. Navision cannot interpret YourTable.Avariable := somestuffs; It has to be YourTable.AfieldFromYouTable := somestuffs; There are no work around for that, Navision cannot simply handle it. I did spend an entire week end a few years back trying to find a solution for this but with no success … I’m sure that those VB like niceties will be implemented in Navision Solutions 9.0. You just have to wait another decade :wink: tarek_demiati@ureach.com Edited by - Tarek Demiati on 2001 May 28 12:09:57

There is no “for each” command in Navision so its long tedious coding. You need to store the primary Key fields for the record the field name and the Prior and New value only if xrec.field <> ‘’,also the User ID, date and time So you would only track changes to key tables “Bank accounts” etc: Pass the xrec and rec to a function compare the fields you want to track and log them! David Cox MindSource (UK) Limited Navision Solutions Partner Email: david@mindsource.co.uk Web: www.mindsource.co.uk

quote:


So you would only track changes to key tables “Bank accounts” etc


You might want to define a global Log-Table which contains the information “Table xxx, Record yyy has been modified by John Doe, June 1st, 2001” and insert a record to this table in OnInsert/OnModify/OnDelete triggers of every table you wish to track changes. However you will loose the information which field has been changed. ------- With best regards from Switzerland Marcus Fabian

quote:


Originally posted by fabian: You might want to define a global Log-Table which contains the information “Table xxx, Record yyy has been modified by John Doe, June 1st, 2001” and insert a record to this table in OnInsert/OnModify/OnDelete triggers of every table you wish to track changes. However you will loose the information which field has been changed. ------- With best regards from Switzerland Marcus Fabian


Remember in code these triggers will only populate the “Changes Log table” if the TRUE is added after the Command CustBankAccount.MODIFY(TRUE); P.S. I have some recent sample code somewhere, contact me if you want a small sample! David Cox MindSource (UK) Limited Navision Solutions Partner Email: david@mindsource.co.uk Web: www.mindsource.co.uk Edited by - David Cox on 2001 Jun 01 09:38:53

I have something similar here. I wanted to have permission rights on each control of a window. WOW !! I know. It’s not realistic. To be more clear, a user can edit 3 controls of a window while another user has no permission to edit the 3 controls. Anyway, I have a table with field Role ID,Table ID,Field ID,Visibility. Role ID is referring table 2000000004,Table ID referring 2000000038, Field ID is referring table 2000000041. On a new window, Role ID and Table ID are giving me a lookup window. However, Field ID has a lookup button but doesn’t give me a lookup window. Can anyone tell me how to go about it? Thanks in advance.

The Field table doesn’t have a default lookup form. Create a new form for this yourself, and call this form in the OnLookup trigger of your field. John

:slight_smile: before make simply log (for insert/update/delete without fields) and collect statistics: how offen somebody read this statistics. This is very huge log and does not contains useful information. I know about one project (not Navision) where this LOG lives about 3 days and after this period was completely removed from system (very huge and unuseful). Do not make paranoics. Business Applications Programmer Sertified Navision Developer SIA “Sintegra” Latvia

Moved from “Attain Developer Forum” to “Attain Developer FAQ” forum.