Compiling Table

How can i compile the table through coding in navision 2013 r2

You have to run finsql.exe with some parameters to do that:

https://msdn.microsoft.com/en-us/library/jj863505(v=nav.71).aspx

In previous versions this can be done using SHELL command, but this command is obsolete in RTC client… you can create a DotNet variable (runonclient=true), System.Diagnostics.Process, this DotNet can run a command line. In Saurav Blog, you have an example on how to use it:

https://saurav-nav.blogspot.com.es/2015/08/nav-2013-later-how-to-run-batch-file.html

Actually i want on action button from RTC as i click on button the table should be compiled.

Why?

Because i have while creating a process entry my erp get closed automatically while selecting the vaiant and then i have to compile the table and do the entry

1- Create a function in the page (or a Codeunit what yo prefer)

2- Create two var DotNet of type “System.Diagnostics.ProcessStartInfo” and “System.Diagnostics.Process” in that function

3- Execute command line using those DotNet var:


Command := ‘[route to finsql.exe]\finsql.exe command=compileobjects, [servername=,] [database=,] [filter=,] [logfile=,] [username=,] [password=,] [ntauthentication=<yes|no|0|1>,] [validatetablechanges=<yes|no>,] [navservername=,] [navserverinstance=,] [navservermanagementport=,] [tenant=]’;

ExecuteBat := ExecuteBat.ProcessStartInfo(‘cmd’, ‘/c "’ + Command + ‘"’); //Provide Details of the Process that need to be Executed.
ExecuteBat.RedirectStandardError := TRUE; // In Case of Error the Error Should be Redirected.
ExecuteBat.RedirectStandardOutput := TRUE; // In Case of Sucess the Error Should be Redirected.
ExecuteBat.UseShellExecute := FALSE;
ExecuteBat.CreateNoWindow := TRUE; // In case we want to see the window set it to False.
Process := Process.Process; // Constructor

Process.StartInfo(ExecuteBat);

Process.Start;



4- Create a button in a Page, and execute that function

I want to Compile a table through RTC, The above example i didn’t understand.

Hi Seemab,

This is a little examble to do this.

OBJECT Table 50500 Table to compile
{
  OBJECT-PROPERTIES
  {
    Date=15/03/18;
    Time=13:05:12;
    Modified=Yes;
    Version List=;
  }
  PROPERTIES
  {
  }
  FIELDS
  {
    { 1   ;   ;Code                ;Code10         }
  }
  KEYS
  {
    {    ;Code                                    ;Clustered=Yes }
  }
  FIELDGROUPS
  {
  }
  CODE
  {

    BEGIN
    END.
  }
}

OBJECT Page 50500 Compile table 50500
{
  OBJECT-PROPERTIES
  {
    Date=15/03/18;
    Time=13:06:47;
    Modified=Yes;
    Version List=;
  }
  PROPERTIES
  {
    SourceTable=Table2000000026;
    PageType=Card;
    ActionList=ACTIONS
    {
      { 1000000003;  ;ActionContainer;
                      ActionContainerType=ActionItems }
      { 1000000004;1 ;Action    ;
                      CaptionML=ESP=Compile table 50500;
                      OnAction=BEGIN
                                 CompileTable50500;
                               END;
                                }
    }
  }
  CONTROLS
  {
    { 1000000000;0;Container;
                ContainerType=ContentArea }

    { 1000000001;1;Group  ;
                Name=General;
                GroupType=Group }

    { 1000000002;2;Field  ;
                SourceExpr=Number }

  }
  CODE
  {

    LOCAL PROCEDURE CompileTable50500@1000000000();
    VAR
      ExecuteBat@1000000001 : DotNet "'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Diagnostics.ProcessStartInfo" RUNONCLIENT;
      Process@1000000000 : DotNet "'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Diagnostics.Process" RUNONCLIENT;
      FinSQLPath@1000000005 : Text;
      ServerName@1000000006 : Text;
      DatabaseName@1000000007 : Text;
      Filter@1000000008 : Text;
      Command@1000000002 : Text;
      Result@1000000003 : Text;
      ErrorMsg@1000000004 : Text;
    BEGIN

      FinSQLPath := '"local path to finsql.exe"';
      ServerName := '"SQL server name and instance"';
      DatabaseName := 'SQL database name';
      Filter := '"Type=Table;ID=50500"';

      Command := FinSQLPath + ' command=compileobjects,servername=' + ServerName + ',database=' + DatabaseName + ',filter=' + Filter;

      ExecuteBat := ExecuteBat.ProcessStartInfo('cmd', '/c "' + Command + '"');     //Provide Details of the Process that need to be Executed.
      ExecuteBat.RedirectStandardError := TRUE;      // In Case of Error the Error Should be Redirected.
      ExecuteBat.RedirectStandardOutput := TRUE;     // In Case of Sucess the Error Should be Redirected.
      ExecuteBat.UseShellExecute := FALSE;
      ExecuteBat.CreateNoWindow := TRUE;             // In case we want to see the window set it to False.
      Process := Process.Process;                    // Constructor
      Process.StartInfo(ExecuteBat);
      Process.Start;
      ErrorMsg := Process.StandardError.ReadToEnd(); // Check Error Exist or Not
      IF ErrorMsg <> '' THEN
        ERROR('%1',ErrorMsg)
      ELSE BEGIN
        Result := Process.StandardOutput.ReadToEnd();// Display the Query in the Batch File.
        MESSAGE('%1',Result);
      END;
    END;

    BEGIN
    END.
  }
}


You have to change objects ID if you want, both table and page have 50500 in Id. Change the following values as you want in page function:

FinSQLPath := ‘“local path to finsql.exe”’;
ServerName := ‘“SQL server name and instance”’;
DatabaseName := ‘SQL database name’;
Filter := ‘“Type=Table;ID=50500”’;

Best regards!!!

ExecuteBat := ExecuteBat.ProcessStartInfo(‘cmd’, ‘/c "’ + Command + ‘"’); Any path i have to write here…

You don’t have to change anything there, you only have to change your values in the following vars:

FinSQLPath := ‘“C:\Program Files (x86)\Microsoft Dynamics NAV\110\RoleTailored Client\finsql.exe”’;
ServerName := ‘“my_sql_server_name”’;
DatabaseName := ‘“my_sql_database_name”’;
Filter := ‘“Type=Table;ID=50500”’;

I only had a problem compiling table the first time. I had to compile table manually, but after that, the table was compiled correctly.

Not working…My navision get closed and i have to compile tthe table from development by pressing F11

Can you execute the command directly in windows command prompt (CMD), and observe if some error is displayed?

In Command prompt How ??

  • First, open command prompt
  • Go to directory where Dynamics NAV is installed, and where there is “finsql.exe” file
  • run the command (first change all between []): “finsql.exe command=compileobjects,servername=”[put_here_sql_server_name_or_ip]",database="[put_here_sql_database_name]",filter=“Type=Table;ID=50500”
  • Comment here the results

Please, remove the first double quote, the one previous finsql.exe, and run command again.

No Error is showing.

Maybe you should lean a little basic command prompt syntax before starting this! That you strings and “” are important and used wrongly. [emoticon:9b0593ccae51484a9fd4cdacd0c90a69]

ok. Thank You

If no error is showing, then seems that table has been compiled… can you check if table has been compiled? I have to say that if the table has never been compiled, I don’t know why, but the table not compile that way.